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

You will write from scratch a class called Heater that represents an adjustable

ID: 3857623 • Letter: Y

Question

You will write from scratch a class called Heater that represents an adjustable thermostat. Follow the detailed steps below. This is based on Exercises 2.93 - 2.94 (6e) / 2.92 - 2.93 (5e) in the book, but with slight modifications, so be sure to follow the instructions below. If you need help getting started, watch Video Note 2.3 (14 mins) from the textbook authors. (However, follow the instructions below when different from the video.)

Create a new BlueJ project named LastName-heater using your last name.

Create a class named Heater

At the top of the source code for Heater, add documentation like this:
/**
* Heater project
* Simulate the behavior of a heater (thermostat)
*
* Modifications:
* List the modifications as you make them
*
* @author Your Name
* @version The Date
*/

Add the following 4 int fields:

temperature

minimum

maximum

increment

Write getters (accessors) and setters (mutators) for each field using standard naming conventions, e.g., getTemperature and setTemperature for the temperature field. You should add a total of 8 methods from this step.

Whenever you add a new method, include a documentation block that describes what the method does. For example:
/**
* @return current temperature of the heater
*/

Modify the setIncrement method so that it does not allow a negative value for the increment. Print an error message if the value given is negative and leave the increment unchanged.

Define two constructors for the class:

The first constructor takes no parameters. In this constructor, initialize minimum to 0, maximum to 100, increment to 1, and temperature to 50.

The second constructor takes 4 parameters and uses them to initialize the fields temperature, minimum, maximum, and increment.

Be sure to add a javadoc documentation block for each constructor.

Define a method named warmer. This method takes no parameters and raises the temperature by the value of the increment field. However, it should not allow the temperature to go above maximum. If the temperature would go above maximum, print an error message and do not raise the temperature.

For example, if temperature=50, increment=3, and maximum=100, after a call to the warmer method, temperature will be 53.

Define a method named cooler. This method takes no parameters and lowers the temperature by the value of the increment field. However, it should not allow the temperature to go below minimum. If the temperature would go below minimum, print an error message and do not lower the temperature.

Adhere to Java style guidelines as described in Appendix J.

Test your code thoroughly! (Don't wait until this step - you should be testing each piece as you go.)

Create a jar file of your project.

Explanation / Answer

/**
* Heater project
* Simulate the behavior of a heater (thermostat)
*
* Modifications:
* List the modifications as you make them
*
* @author soban
* @ 17/7/2017
*/

public class Heater{
private int temperature;
private int minimum;
private int maximum;
private int increment;

/**
* @return current temperature of the heater
*/
public int getTemperature(){
return temperature;
}

/**
* @sets the current temperature of the heater
*/
public void setTemperature(int t){
temperature=t;
}

/**
* @ gets the minimum temperature of the heater
*/
public int getMinimum(){
return minimum;
}

/**
* @ sets the minimum temperature of the heater
*/
public void setMinimum(int t){
minimum=t;
}

/**
* @ gets the maximum temperature of the heater
*/
public int getMaximum(){
return maximum;
}

/**
* @ sets the maximum temperature of the heater
*/
public void setMaximum(int t){
maximum=t;
}

/**
*@ gets the increment temperature of the heater
*/
public int getIncrement(){
return increment;
}

/**
*@ sets the increment temperature of the heater
*/
public void setIncrement(int t){
if(t>=0)
increment=t;
else
System.out.println(" Error: Increment value is negative");
}

/**
*@ Default constructor
*/
public Heater()
{
minimum=0;
maximum=100;
increment=1;
temperature=50;
}


/**
*@ Parameterised constructor
*/
public Heater(int min, int max, int incr, int temp){
minimum=min;
maximum=max;
increment=incr;
temperature=temp;
}

/**
*@ method raises the temperature by the value of increment field
*/
public void warmer()
{
//checking the temperature should not cross the value 100
if( temperature + getIncrement() >100)
System.out.println(" Error : Temperature above 100");
else
// increment the temperature
temperature += getIncrement();
}

/**
*@ method decreases the temperature by the value of increment field
*/
public void cooler()
{
//checking the temperature should not below the value 0
if( temperature - getIncrement() < 0)
System.out.println(" Error: Temperature is below 0");
else
//decrement the temperature
temperature -= getIncrement();
}
}

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