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.
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 :

USING BLUEJ: You will write from scratch a class called Heater that represents an adjustable thermostat....
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 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 - 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 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 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 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 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'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 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 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...