Question: JAVA The class will be called Temp Add a compareTo method. (returns -1 if the invoking object has a lower temp, 0 if the same,

JAVA The class will be called Temp Add a compareTo method. (returns -1 if the invoking object has a lower temp, 0 if the same, 1 if larger) Add a static counter (object id)to keep track of how many Temperature objects have been created(1,2,3,...) Add a static method, getTempCount, to return how many Temp objects have been created. Include a toString method that displays the object as follows(assumes 3rd one created): Object Id: 3 Temperature in F: 32.0 Temperature in C: 0.0 Note that calling getF or getC returns the value only. They do not change the native data. To be clear, the only methods are as follows: 4 constructors, getF, getC, setDegrees, setScale, equals, toString, compareTo and a static getTempCount that returns the total number of objects that have been created. Optionally, you may supply simple getters for degrees and scale (getDegrees, getScale). Note that the getters will return the degrees in the requested scale rounded to a tenth of a degree. Never round the native data. Note that the equals method will return true if the temperatures are the same when compared in celsius (that was rounded to a tenth of a degree). Be sure to make great use of this() and have only one constructor do any real work. Be sure to validate the scale and follow the default (C) if a "bad scale" is sent in No need to validate the degrees and worry about things such as absolute zero and so on. NOTE: The Temp class must work correctly with the TestTemp class supplied below  32 - 212 180 ticks 0-100 1/10 public class Temp { } public class TestTemp { public static void main(String [] args) { // only one constructor does any real work Temp temp1 = new Temp(); // 0 C Temp temp2 = new Temp(32); // 32 C Temp temp3 = new Temp('F'); // 0 F Temp temp4 = new Temp(32, 'F'); // 32 F Temp temp5 = new Temp(); // 0 C temp5.setDegrees(10); temp5.setScale('F'); // 10 F System.out.println("C: " + temp1.getC() ); // C: 0.0 System.out.println("F: " + temp1.getF() ); // F: 32.0 System.out.println(temp1.equals(temp4)); // true System.out.println(temp1.equals(temp2)); // false System.out.println("You have " + Temp.getTempCount() ); // You have 5 if( temp3.compareTo(temp5)< 0 ) //temp3 is lower than than temp5 { System.out.println("temp3 is lower than than temp5"); } else { System.out.println("temp3 is same or larger than temp5"); } System.out.println(temp1); /* TEMP OBJECT #1 IN C: 0.0 IN F: 32.0 */ 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!