Question

USING BLUEJ: You will write from scratch a class called Heater that represents an adjustable thermostat....

USING BLUEJ:

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.

  1. Create a new BlueJ project named LastName-heater using your last name.
  2. 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
      */
  3. Add the following 4 int fields:
    • temperature
    • minimum
    • maximum
    • increment
  4. 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.
  5. 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.
  6. 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.
    • If temperature=98, increment=3, and maximum=100, after a call to the warmer method, temperature is still 98 and an error message is printed.
  7. 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.
  8. Adhere to Java style guidelines as described in Appendix J.
  9. Test your code thoroughly! (Don't wait until this step - you should be testing each piece as you go.)
  10. Create a jar file of your project.
    1. From BlueJ, choose Project->Create Jar File...
    2. Check the "Include source" check box
    3. Name the file LastName-heater
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code for the following question :

Code :

/*
heater class
*/
class Heater
{
//instance variable
private int temperature;
private int minimum;
private int maximum;
private int increment;
  
/*
@constructor default to initialize instance variable
*/
public Heater()
{
this.temperature = 50;
this.minimum = 0;
this.maximum = 100;
this.increment = 1;
}
  
/*
@constructor parameterized to set all instance variables
*/
public Heater(int temperature, int minimum, int maximum, int increment)
{
this.temperature = temperature;
this.minimum = minimum;
this.maximum = maximum;
this.increment = increment;
}
  
/*
@setter method for all instance variables
*/
public void setTemprature(int temperature)
{
if(temperature > 100)
{
System.out.println("Erro! Can not set temperature above 100");
}
else
{
this.temperature = temperature;
}
}
  
public void setMin(int minimum)
{
this.minimum = minimum;
}
  
public void setMax(int maximum)
{
this.maximum = maximum;
}
  
public void setIncrement(int increment)
{
if( increment < 0)
{
System.out.println("Error! increment can not be a negative value");
}
else{
  
this.increment = increment;
}
}
  
  
/*
@getter method for all instance variables
*/
public int getTemprature()
{
return temperature;
}
  
public int getMinimum()
{
return minimum;
}
  
public int getMaximum()
{
return maximum;
}
  
public int getIncreamnet()
{
return increment;
}
  
/*
@method warmer method to increment the temperature
*/
public void warmer()
{
//check if inresing temp exceed maximum value
if(this.temperature + this.increment <= 100)
{
this.temperature += this.increment;
}
else
{
System.out.println("Error! Can not increase temperature above maximum value");
}
}
  
/*
@method cooler to deecrese the temperature
*/
public void cooler()
{
//check if decreament voilate minimum temperature value
if(this.temperature - this.increment < minimum)
{
System.out.println("Error! temperature can not be lower than minimum value");
}
else
{
this.temperature -= this.increment;
}
}
  
/*
@toString() method
*/
public String toString()
{
String str = "Temp : "+getTemprature() + "\nMin : "+getMinimum() + "\nMax :"
+ getMaximum() + "\nIncreament : "+ getIncreamnet();
return str;
}
}
public class Main
{
   public static void main(String[] args) {
     
   /*
   @object of Heater class
   */
     
   Heater heater1 = new Heater();
     
   //print the object 1
   System.out.println("Object 1 :\n" + heater1.toString());
     
   Heater heater2 = new Heater(10, 0, 100, 4);
     
   //print the object 2
   System.out.println("\nObject 2 :\n"+heater2.toString());
     
   //set the object heater1
   heater1.setTemprature(96);
   heater1.setIncrement(4);
   heater1.setMax(100);
   heater1.setMin(0);
     
   //warmer 96 + 4 = 100
     
   heater1.warmer();
     
   System.out.println("\nTemprature 1: "+ heater1.getTemprature());
     
   //when we call again it will throw Error beacuse 100 + 4 = 104 greater than maximum
   heater1.warmer();
     
   //here Temprature will not increase beacuse of Error
   System.out.println("Temprature 1: "+ heater1.getTemprature() );
     
     
     
   //lets call cooler on heater2
   heater2.cooler(); //10 - 4 = 6
   System.out.println("Temprature 2: "+ heater2.getTemprature());
     

heater2.cooler(); //6 - 4 = 2     
System.out.println("Temprature 2: "+ heater2.getTemprature());
     

heater2.cooler(); //2 - 4 = -2 less than minimum, will throw Error
   System.out.println("Temprature 2: "+ heater2.getTemprature());
     
   }
}


--------------------------------------------------------------------------------------------------------------------------------------------------

Output :

Add a comment
Know the answer?
Add Answer to:
USING BLUEJ: You will write from scratch a class called Heater that represents an adjustable thermostat....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • java bluej Create a class called Vehicle, that contains five fields, current speed, power, accelerate, decelerate...

    java bluej Create a class called Vehicle, that contains five fields, current speed, power, accelerate, decelerate and top speed, all of which type is int.  Define a constructor that takes and sets the accelerate, decelerate; sets the power to 20, and top speed to 120. Leave the current speed as 0. Also define a constructor that takes no parameters. The power field should be set to the value of 30 in this constructor, top speed to 160, and accelerate and decelerate...

  • Write a class called Book. Here are the relevant attributes: title author yearPublished            bookPriceInCAD Provide...

    Write a class called Book. Here are the relevant attributes: title author yearPublished            bookPriceInCAD Provide a constructor that takes parameters to initialize all the instance variables. The constructor calls the mutator (set) methods to initialize the instance variables. Provide an accessor (get) and mutator (set) for each instance variable. The mutators all validate their parameters appropriately and use them only if valid. If the passed parameter was invalid an IllegalArgumentException will be thrown with a proper error message A...

  • Write a class called Student. The specification for a Student is: Three Instance fields name -...

    Write a class called Student. The specification for a Student is: Three Instance fields name - a String of the student's full name totalQuizScore - double numQuizesTaken - int Constructor Default construtor that sets the instance fields to a default value Parameterized constructor that sets the name instance field to a parameter value and set the other instance fields to a default value. Methods setName - sets or changes the student name by taking in a parameter getName - returns...

  • Create a new project in BlueJ and name it LastName-lab8-appstore, e.g., Smith-lab8-appstore. If your App class from Lab 4 is fully functional, copy it into the project. (You can drag a file from File...

    Create a new project in BlueJ and name it LastName-lab8-appstore, e.g., Smith-lab8-appstore. If your App class from Lab 4 is fully functional, copy it into the project. (You can drag a file from File Explorer onto the BlueJ project window.) Otherwise, use the instructor's App class: Create a new class using the "New Class..." button and name it App. Open the App class to edit the source code. Select and delete all the source code so that the file is...

  • In this homework, you will create a class that stores a list of transactions and computes...

    In this homework, you will create a class that stores a list of transactions and computes the average transaction for a given month. The user must input the name of the month and the transactions into the terminal. The Transaction_List Class First you will create two C++ files called abc1234_Transaction_List.h and abc1234_Transaction_List.cpp. Below is a UML class diagram that shows the basic design of the Transaction_List class. Transaction List -month : string transactions: vector-sdouble - num transactions: int +Transaction Listim...

  • Suppose you were given the job to write a Java class to manage employee payroll information...

    Suppose you were given the job to write a Java class to manage employee payroll information in an HR management system. Each employee will be modeled as a single EmployeePayroll object (much like the Student objects discussed in class). The state of the EmployeePayroll object includes the first name and last name of the employee, a unique 15 digit employee number for each employee, a number of hours that they've worked this week (which could be a fraction of an...

  • Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete...

    Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete programs using two classes: client and supplier 2   User Interface Specification This is a console-based I/O program. Display should go to System.out (print or println) and the program will get user input using the Scanner class. The flow of execution should be as follows: When the program starts, display a one-line introduction to the user Display a menu with 5 options 1. validate zip...

  • ise 1. Create a new project named lab6 1. You will be implementing an IceCream class. For the class attributes, let&#39...

    ise 1. Create a new project named lab6 1. You will be implementing an IceCream class. For the class attributes, let's stick to flavor, number ofscoops, and price (in cents). Note that the price per scoop of any flavor is 99 cents. Therefore, allow the flavor and scoops to be set directly, but not the price! The price should be set automatically based on the number of scoops entered. Some other requirements i. A default constructor and a constructor with...

  • Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an...

    Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an order at a fast-food burger joint. This class will be used in Part B, when we work with a list of orders. As vou work through this part and Part B, draw a UML diagram of each class in using the UML drawing tool 1) Create a new Lab5TestProject project in Netbeans, right-click on the lab5testproject package and select New>Java Class 2) Call your...

  • // Client application class and service class Create a NetBeans project named StudentClient following the instructions...

    // Client application class and service class Create a NetBeans project named StudentClient following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. Add a class named Student to the StudentClient project following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. After you have created your NetBeans Project your application class StudentC lient should contain the following executable code: package studentclient; public class...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT