This is the Program I am try create !
Create a class CoffeeCup with a double instance variable temperature. Provide a parameterized constructor, an accessor/getter, and a mutator/setter. It may be noted that 75 degree Celsius is considered best temperature for coffee to be served for drinking.
Create another class TeaCup with a double instance variable temperature. Provide a parameterized constructor, an accessor/getter, and a mutator/setter. It may also be noted that 70 degree Celsius is considered best temperature for tea to be served for drinking.
Create TemperatureException, TooColdException, and TooHotException classes as drawn in the exception hierarchy below. Each exception class should include a default constructor and a parameterized constructor with one String parameter. Also override toString method in each exception class to return description of exception.
Create another class VirtualPerson with methods drinkCoffee(CoffeeCup acup) and drinkTea(TeaCup acup), each of which should throw TooColdException or TooHotException respectively if the coffee or tea to be served is either too cold or too hot. 65 degree Celsius should be considered too cold temperature for coffee and 85 degree Celsius should be considered too hot temperature for coffee. Similarly, 60 degree Celsius should be considered too cold temperature for tea and 80 degree Celsius should be considered too hot temperature for tea.
Create another class VirtualCafe with a static method serveCustomer(VirtualPerson customer, CoffeeCup acup) overloaded as serveCustomer(VirtualPerson customer, TeaCup acup). First version should invoke drinkCofee and second should invoke drinkTea method of VirtualPerson from within a try block. Each catch block should display description of exception along with the stack trace.
Write a main class to test your VirtualCafe. Inside main method, provide a console-based menu with following functionalities:
• Creating a virtual customer
• Reading a double type value from user representing temperature of coffee cup and constructing a coffee cup with that value
• Reading a double type value from user representing temperature of tea cup and constructing a tea cup with that value
• Serving a customer with a cup of coffee or tea as ordered
here is the code.
CoffeeCup
package Cafe;
public class CoffeeCup {
double tempreture;
void setTempreture(double t){
tempreture=t;
}
double getTempreture(){
return tempreture;
}
CoffeeCup(double t){
tempreture=t;
}
CoffeeCup(){
tempreture=75;
}
}
TeaCup
package Cafe;
public class TeaCup {
double tempreture;
void setTemreture(double t){
tempreture=t;
}
double getTemreture(){
return tempreture;
}
TeaCup(double t){
tempreture=t;
}
TeaCup(){
tempreture=70;
}
}
and the problem code is here....toString() method is not overriding give error 'attempting to assign weaker access privileges;was public'.
TemperatureException
package java.Exception;
public class TemperatureException {
TemperatureException(){
}
TemperatureException(String ex){
System.out.println(ex);
}
void toString(){
TemperatureException e=new TemperatureException();
System.out.print(e);
}
}