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

A class has four fields; temperature, min, max, and increment. They are all of i

ID: 3801803 • Letter: A

Question

A class has four fields; temperature, min, max, and increment. They are all of int type. write a method to compare two class objects using equals method in Java. And if there is a method called setCooler in this class, how to execute this cooler method in different class that has main method. This is a basic java question, so, I am looking for basic answer to understand how things work. Finally, how to create insance fo previous class in main method and display temperature using getTemperature method in main method. Can somebody clearly explain this for me.

Explanation / Answer

TemperatureTest.java


public class TemperatureTest {

  
   public static void main(String[] args) {
       Temperature t = new Temperature();
       t.setCooler(24);
       t.setMax(30);
       t.setMax(17);
       System.out.println("Present Temparature: "+t.getTemperature());
       t.setIncrement(3);
       System.out.println("Now Temparature: "+t.getTemperature());

   }

}

Temperature.java


public class Temperature {
   private int temperature, min, max,increment;
   public Temperature() {
      
   }
   public Temperature(int temperature, int min,int max,int increment) {
       this.temperature = temperature;
       this.min = min;
       this.max = max;
       this.increment = increment;
   }
   public int getTemperature() {
       return temperature;
   }
   public void setCooler(int i){
       temperature = i;
   }
   public int getMin() {
       return min;
   }
   public void setMin(int min) {
       this.min = min;
   }
   public int getMax() {
       return max;
   }
   public void setMax(int max) {
       this.max = max;
   }
   public int getIncrement() {
       return increment;
   }
   public void setIncrement(int increment) {
       temperature = temperature + increment;
       this.increment = increment;
   }
  
}

Output:

Present Temparature: 24
Now Temparature: 27

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