
/**
 * The class CS302_Cafe provides a solution to the problem posed in
 * discussion on 2/2.  Try changing names, adding ingredients and
 * whatever else you can think of.  See how your changes affect the
 * results.
 *
 * Author :  Andrew Hutcheson
 * Date   :  February 2, 2001
 * Course :  302
 */
 
									      
public class CS302_Cafe {

    public static void main(String[] args){

	// The Cast
	Cafe gungaDiner = new Cafe("The Gunga Diner");
	Chef truffles = new Chef("Chef Truffles");
	Waiter robT6 = new Waiter("WaiterRob T6");
	Patron archimedes = new Patron("Archimedes of Syracuse");
	
	// Act I

	// The chef and waiter enter the cafe.
	gungaDiner.addChef(truffles);
	gungaDiner.addWaiter(robT6);
	
	// A patron enters the cafe.
	gungaDiner.addPatron(archimedes);
	
	// The patron gives his/her order to the waiter.
	archimedes.giveOrder(robT6);
	
	// The waiter delivers the order to the chef.
	robT6.giveOrder(truffles);
	
	// The chef prepares the food.
	truffles.addFood(new Ingredient("Soylent Green"));
	Ingredient chilton = new Ingredient("Frederick Chilton");
	truffles.addFood(chilton);

	// The chef gives the food to the waiter.
	truffles.giveFood(robT6);
	
	// The waiter gives the food to the patron.
	robT6.giveFood(archimedes);
	
	// The paron eats, pays and leaves.
	archimedes.eat();
	archimedes.pay(robT6);
	gungaDiner.removePatron();
    }
}

/**
 * If you get bored playing with the class above you can try
 * modifying these underlying classes. See if you can figure out
 * what "extends" and why the "toString" method is defined.
 */

class Named {

    protected String name;

    protected Named(String s){
	name = s;
    }

    public String toString(){
	return name;
    }
}

class Cafe extends Named {

    Cafe(String s){
	super(s);
    }

    void addChef(Chef c){
	System.out.println("A chef, " + c + ", enters the cafe.");
    }

    void addWaiter(Waiter w){
	System.out.println("A waiter, " + w + ", enters the cafe.");
    }

    void addPatron(Patron p){
	System.out.println("A patron, " + p + ", enters the cafe.");
    }

    void removePatron(){
	System.out.println("A patron leaves the cafe.");
    }
}

class Chef extends Named {
    
    Chef(String s){
	super(s);
    }

    void addFood(Ingredient i){
	System.out.println(name + " adds " + i + " to the food.");
    }

    void giveFood(Waiter w){
	System.out.println(name + " gives the food to the waiter, " + w + ".");
    }
}

class Waiter extends Named {

    Waiter(String s){
	super(s);
    }

    void giveOrder(Chef c){
	System.out.println(name + " gives an order to the chef, " + c + ".");
    }

    void giveFood(Patron p){
	System.out.println(name + " gives food to the patron, " + p + ".");
    }
}

class Patron extends Named {
    
    Patron(String s){
	super(s);
    }

    void giveOrder(Waiter w){
	System.out.println(name + " gives an order to the waiter, " + w + ".");
    }
    
    void eat(){
	System.out.println(name + " eats some food.");
    }

    void pay(Waiter w){
	System.out.println(name + " pays the waiter, " + w + ".");
    }
}

class Ingredient extends Named {
    
    Ingredient(String s){
	super(s);
    }
}
