3dfsa
Post on 08-Dec-2015
212 Views
Preview:
DESCRIPTION
TRANSCRIPT
Name: Sanju Singh
Roll No: B12ITA060
Assignment No: 3
MainSys.java
public class MainSys{
public static void main(String[] args) {
Customer customer= new Customer();
customer.getMenu();
customer.serveOrder();
customer.payBill();
}
}
Customer.java
import java.io.*;
public class Customer{
private String name;
private State state;
public void getMenu(){
Boolean done=false;
String str;
setState(State.SELECTING_FOODITEMS);
System.out.println("\nCurrent State: SELECTING FOODITEMS");
System.out.print("\nPress key if Done: ");
try{
BufferedReader r = new BufferedReader (new InputStreamReader (System.in));
str=r.readLine();
}catch(Exception e){}
done=true;
if(done){
setState(State.ORDERING);
System.out.println("\nCurrent State: ORDERING");
}
setState(State.WAITING);
System.out.println("\nCurrent State: WAITING");
}
public void serveOrder(){
Boolean done=false, orderMore=false;
Integer choice=1;
String str;
setState(State.EATING);
System.out.println("\nCurrent State: EATING");
System.out.print("\nPress 1 if Done & 2 for Ordering More: ");
try{
BufferedReader r = new BufferedReader (new InputStreamReader (System.in));
str=r.readLine();
choice=Integer.parseInt(str);
}catch(Exception e){}
if(choice==1)
done=true;
else
orderMore=true;
if(done){
setState(State.WAIT_FOR_BILL);
System.out.println("\nCurrent State: WAIT FOR BILL");
}
else if(orderMore){
getMenu();
serveOrder();
}
}
public void payBill(){
setState(State.BILL_PAID);
System.out.println("\nCurrent State: BILL PAID");
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setState(State state) {
this.state = state;
}
}
State.java
public enum State {
SELECTING_FOODITEMS, ORDERING, WAITING, EATING, WAIT_FOR_BILL, BILL_PAID
}
OUTPUT
Current State: SELECTING FOODITEMS
Press key if Done: 1
Current State: ORDERING
Current State: WAITING
Current State: EATING
Press 1 if Done & 2 for Ordering More: 2
Current State: SELECTING FOODITEMS
Press key if Done: 1
Current State: ORDERING
Current State: WAITING
Current State: EATING
Press 1 if Done & 2 for Ordering More: 1
Current State: WAIT FOR BILL
Current State: BILL PAID
top related