Design and implement a program that determines if the water used to brew coffee
ID: 646749 • Letter: D
Question
Design and implement a program that determines if the water used to brew coffee is tile correct temperature. Tile program asks a user to input tile water temperature to brew coffee. . If tile water is less than 88 Degree C. tile program should throw a Tooco ld Exception. Tile program should catch tile exception and show a message stating tile temperature should be at least 88 Degree C. . If the water is between 88 Degree C and 93 Degree C. tile program should show a message stating that tile temperature is fine for brewing. . If the water is above 93 Degree C. the program should throw a Too Hot Exception. The program should catch the exception and show a message stating that the temperature should be less than 93 Degree CExplanation / Answer
package myExceptions;
public class TooColdException extends Exception{
public TooColdException(String exc)
{
super(exc);
}
public String getMessage()
{
return super.getMessage();
}
}
public class TooHotException extends Exception{
public TooHotException(String exc)
{
super(exc);
}
public String getMessage()
{
return super.getMessage();
}
}
import myExceptions.TooColdException;
import myExceptions.TooHotException;
public class checkException {
public static void main(String args[])
{
try
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter water temperature");
int temp = sc.nextInt();
if(temp<88){
throw new TooColdException("Temperature should be atleast 88 oC");
}
else if(temp>93){
throw new TooHotException("Temperature should be less than 93 0C");
}
else{
System.out.println("Temperature is fine for brewing!!");
}
}
catch(MyException myEx)
{
System.out.println("This is my coffee brewing exception:" + myEx.getMessage());
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.