Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a new project in Eclipse called Temperature. Within that project, define

ID: 3889105 • Letter: C

Question

Create a new project in Eclipse called Temperature. Within that project, define a class that represents a Temperature object. It should contain two instance variables. One variable will hold the current temperature and the other variable is used to indicate whether the temperature is maintained in Farenheit or Celsius. The temperature variable will be type double, and the other variable will be type char. Create public methods to get and set both of these variables.

Use the Riddle class as a model.

Create a driver class, TemperatureUser, that creates two instances of Temperature. The first instance will have a value of 70 degrees Farenheit and the second 32 degrees Celsius.

Upload your Java class files (Temperature.java and TemperatureUser.java)

Extra Credit: Review the description of the toString() method in the Object specification (http://docs.oracle.com/javase/8/docs/api/java/lang/Object.html). This method is inherited from the Object superclass. Write a new toString() method for the Temperature class that displays the temperature on the console.

ANY HELP ON THIS ONE WILL BE GREATLY APPRECIATED! Thanks in Advance

Explanation / Answer

Classes are:

*************temperature.java*********************

public class Temperature {
   private double current_temperature;
   private char type;

   public double getCurrent_temperature() {
       return current_temperature;
   }
   public void setCurrent_temperature(double current_temperature) {
       this.current_temperature = current_temperature;
   }
   public char getType() {
       return type;
   }
   public void setType(char type) {
       this.type = type;
   }
   @Override
   public String toString() {
       return ""+current_temperature+""+type;     // writing both tempertaure and type in string form and returning it as String
   }
}

***********************TemperatureUser.java***********************************

public class TemperatureUser {

   public static void main(String[] args)
   {
       Temperature t1=new Temperature();       //instance 1 of temperature class
       Temperature t2=new Temperature();       //instance 2 of temperature class
      
       t1.setCurrent_temperature(70); // for setting current temperature to 70 for instance t1
       t1.setType('F'); // as temperature unit is farenheit
       t2.setCurrent_temperature(32); //same as above, temp 32 degree
       t2.setType('C'); // for degree celcius unit
       System.out.println(t1.toString()); // toString use in driver class
      
   }
}

************************************************************************************************************************

Now whatever written above is solution including part for extraa credits, now let me explain you what i did there, created a class Temperature, then created two instance variables which can also be called global variables, then added getter and setter methods, setter method is for to assign a value to variable, basically setting a value and getter method is for getting value of that variable, for shortcut (in eclipse right click on program window and select source, after than in new list you will see getter and setter option click that and you are good to go)

in second class, TemperatureUser, as this is driver class we need main() method to operate, t1 and t2 are instances of temperature class and rest is written in code itself

enjoy ...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote