Question: Java A: Write an Exception class called TemperatureTooLow.java that will be used in the following program. B: Write a class called Fridge.java, which has an
Java A: Write an Exception class called TemperatureTooLow.java that will be used in the following program.
B: Write a class called Fridge.java, which has an instance variable called temperature of type int and the following methods:
public void setTemp(int temp){ ... }
public boolean tempNormal(){ ... }
The setTemp method sets the temperature instancevariable. When tempNormal method is called, if temperature < 10, it throws TemperatureTooLow Exception otherwise returns true.
C: Write a TempTest.java class that does the following:
1 - Creates an instance of the Fridge class.
2 - Calls the setTemp method to set the fridges temperature to 35 and then prints the result of calling tempNormal method.
3 - Next it Calls the setTemp method again to set the fridges temperature to 8 and again prints the result of calling tempNormal method.
4 - In steps 2 and 3, the tempTest.java class should catch the TemperatureTooLow Exception where required.
5 - The TemperatureTooLow Exception shows the current temperature of the fridge when thrown.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
