Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Using the attached code, change the package name ac accordingly

Using the attached code, change the package name ac accordingly

Computer Science

Using the attached code, change the package name ac accordingly. Each instance of the Temperature class is intended to provide the temperature in Kelvin, Celsius (Centigrade), and Fahrenheit degrees, and also to allow controlled manipulation of the temperature in any of these scales. The constants in the code will help you convert from one scale to another. Implement the following methods: 

 

Temperature() - default constructor should initialize the temperature to 0 degrees Celsius 

Temperature(double c) - constructor with one double parameter should initialize the temperature to c degrees Celsius getTempK() - return the Kelvin value of the temperature currently stored in the object 

getTempC() - return the Celsius value of the temperature currently stored in the object 

getTempF() - return the Fahrenheit value of the temperature currently stored in the object 

incrC(float v) - increment the internal temperature by v Celsius degrees (do not allow the temperatture to go below 0 degrees Kelvin)

incrF(float v) - increment the internal temperature by v Fahrenheit degrees (do not allow the temperatture to go below 0 degrees Kelvin) 

setTempK(float v) - set the temperature currently stored in the object to v degrees Kelvin 

setTempC(float v) - set the temperature currently stored in the object to v degrees Celsius 

setTempF(float v) - set the temperature currently stored in the object to v degrees Fahrenheit

toString() - use String.format(format-string, arguments-to-be-formatted) with the format specification used by printf() to produce a string representation of the class, displayed at the end as below. 

The relations between the temperature scales are given by: C = K - 273.15 C = 5 * (F - 32) / 9 

 

If the code is correct, when ran, the program should display : 

edu.Morganstate.cisy2133.your_last_name.Assign13 . . . 30 test messages . . . [internal=310.15,K=310.15,C=37.00,F=98.60] errors:0

 

package edu.Morganstate.cisy2133.your_last_name;
class Assign13
{
    private int _errs;
    private void test(Temperature tmp, int phase, double[] testValues)
    {
        int test;
        double target;
        String[] testMsgs =
        {
            "temp C",
            "temp F",
            "temp K",
        };
        String failedMsg = "  -> test %d failed", cmpMsg = " expected:%.2f actual:%.2f", testMsg = "test %d ";
        for (test = 0; test < testValues.length; ++test)
        {
            switch (test % testValues.length) // set values for particular tests
            {
            case 3:
                tmp.incrF(180.0);
                break;
            case 6:
                tmp.incrC(-100.0);
                break;
            case 9:
                tmp.setTempK(0.0);
                break;
            case 12:
                tmp.setTempF(98.6);
                break;
            }
            switch  (test % 3)
            {
            case 0:
                target = tmp.getTempC();
                break;
            case 1:
                target = tmp.getTempF();
                break;
            default:
                target = tmp.getTempK();
                break;
            }
            System.out.printf(testMsg + testMsgs[(test + phase) % 3] + cmpMsg + "n",
                test + phase, testValues[test], target);
            if (Math.abs(testValues[test] - target) > 0.000001)
            {
                System.out.printf(failedMsg + "n", test + phase);
                ++_errs;
            }
        }
    }
    public static void main(String[] args)
    {
        double[] testValues = { 0, 32, 273.15, 100, 212, 373.15, 0, 32, 273.15, -273.15, -459.67, 0, 37, 98.6, 310.15};
        double[] testValues2 = { 5, 41, 278.15, 105, 221, 378.15, 5, 41, 278.15, -273.15, -459.67, 0, 37, 98.6, 310.15};
        Assign13 a13 = new Assign13();
        Temperature tmp;
        System.out.println(Assign13.class.getCanonicalName());
        tmp = new Temperature();
        a13.test(tmp, 0, testValues);
        tmp = new Temperature(5.0);
        a13.test(tmp, 15, testValues2);
        System.out.printf("%sn", tmp);
        System.out.printf("errors:%dn", a13._errs);
    }
    public static class Temperature
    {
        private final double ToC = 273.15;
        private final double FtoCratio = 5.0 / 9.0;
        private final double CtoFratio = 9.0 / 5.0;
        private final double Foffset = 32.0;
        private double internal_temp; // temperature in your base scale
        public Temperature()  // init to 0 Celsius
        {

        }
        public Temperature(double tc) // init to a Celsius temperature tc
        {
        }
        public double getTempK()
        {
            return 0.0;
        }
        public void setTempK(double tmp)
        {
        }
        public double getTempC()
        {
            return 0.0;
        }
        public void setTempC(double tmp)
        {
        }
        public double getTempF()
        {
            return 0.0;
        }
        public void setTempF(double tmp)
        {
        }
        private void Incr(double incr)
        {
            if ((internal_temp += incr) < 0)
                internal_temp = 0.0;
        }
        public double incrC(double incr)
        {
            this.Incr(incr);
            return getTempC();
        }
        public double incrF(double incr)
        {
            incrC(FtoCratio * incr);
            return getTempF();
        }
        public String toString()
        {
            return String.format("", internal_temp, getTempK(), getTempC(), getTempF());
        }
    }
}

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE