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....
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 BlueJ, create “New Project” named LASTNAME-company Use good programming style and Javadoc documentation standards Create a “New Class…” named Company to store the employee mappings of employee names (Key) to employee ids (Value) Declare and initialize class constants MIN and MAX to appropriate values Declare and instantiate a Random randomGenerator field object Declare a String field named name for the company’s name Declare a HashMap<String, String> field named employees Add a constructor with only 1 parameter named name...
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...
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...
Here is the UML for the class Contact -fullName : string -phoneNum: string -emailAddress : string +Contact() //default constructor sets all attribute strings to “unknown”; no other constructor +setName(string name) : void +setPhone(string pn) : void +setEmail(string em) : void +getName() : string +getPhone() : string +getEmail() : string +printContact() : void //print out the name, phone numbers and email address Create New Project Name your project: CIS247_Lab7_YourLastName. For this exercise, you may use a header file or one file...
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...
Computer Science 111 Introduction to Algorithms and Programming: Java Programming Net Beans Project #4 - Classes and Objects (15 Points) You will create 3 new classes for this project, two will be chosen (THE TWO CHOSEN ARE TENNIS SHOE AND TREE) from the list below and one will be an entirely new class you invent. Here is the list: Cellphone Clothes JuiceDrink Book MusicBand Bike GameConsole Tree Automobile Baseball MusicPlayer Laptop TennisShoe Cartoon EnergyDrink TabletComputer RealityShow HalloweenCostume Design First Create...