Site hosted by Angelfire.com: Build your free website today!
       
The Digital Reference Section

The grocery Object

public class grocery{

public static void main(String[] arg){

product luckyMe,alpo,ligo;
shoppingCart cart;
customer peter;
cashier christine;
wallet seiko;
counter fastLane;
cashRegister panasonic;

cart = new shoppingCart();
luckyMe = new product("noodles",10);
alpo = new product("dog-food",75);
ligo = new product("canned-goods",15);

peter = new customer();
seiko = new wallet(1000);
christine = new cashier();
fastLane = new counter();
panasonic = new cashRegister();


peter.speak("How much money do I have in my seiko wallet?");
peter.look(seiko);

peter.speak("I'll take this ligo sardine");
peter.get(ligo);
peter.look(peter.hand);
peter.putTo(cart);

peter.speak("I'll take this alpo dogfood");
peter.get(alpo);
peter.look(peter.hand);
peter.putTo(cart);

peter.speak("I'll take this lucky Me noodles");
peter.get(luckyMe);
peter.look(peter.hand);
peter.putTo(cart);

peter.speak("Hmm.. I think this will be all...");
peter.look(cart);

peter.hold(cart);

fastLane.getCart(peter.otherHand);

christine.speak("Good day Sir!!!");
peter.speak("It's really a good day today Christine");
peter.smile();
christine.speak("Yes, your right! It's a good day today");
christine.smile();

christine.getCart(fastLane);

christine.speak("1st Product");
christine.getProduct();
christine.rightHand.inquire();
panasonic.accumulate(christine.rightHand);

christine.speak("2nd Product");
christine.getProduct();
christine.rightHand.inquire();
panasonic.accumulate(christine.rightHand);

christine.speak("3rd Product");
christine.getProduct();
christine.rightHand.inquire();
panasonic.accumulate(christine.rightHand);

peter.speak("My total amount due is...");
peter.look(panasonic);
peter.speak("Take my money...");

christine.speak("give me your wallet");
christine.closeTransaction(panasonic,seiko);

peter.speak("my money left is...");
peter.look(seiko);

christine.speak("Thank you sir, come again");
peter.speak("OK, thanks too");
peter.speak("see you again");
peter.smile();
christine.smile();

}

}

The customer object

public class customer{

public product hand;
public shoppingCart otherHand;

customer(){


}

public void speak(String phrase){

System.out.println(phrase+" (customer) ");

}

public void smile(){

System.out.println(":)");

}


public void look(wallet w){

w.balance();

}

public void look(product p){

if (p==null){
}
if (p!=null){
p.inquire();
}

}

public void look(shoppingCart s){

s.inquire();

}

public void look(cashRegister c){

c.lcdDisplay();

}

public void get(product p){

hand = p;

}

public void hold(shoppingCart s){

otherHand=s;

}

public void putTo(shoppingCart c){

c.getProduct(hand);
hand = null;

}


public void release(){

otherHand=null;
hand=null;

}


}

The product object

public class product{

public String category;
public double price;

product(String c, double p){

category=c;
price=p;

}

public void inquire(){

System.out.println(category+" "+price);

}

}

The shoppingcart object

public class shoppingCart{

product[] location;
int ptr;

shoppingCart(){

location = new product[10];
ptr=0;

}

public void getProduct(product p){

location[ptr]=p;
ptr++;


}

public void inquire(){

int x = location.length;
for(int y=0;y<=x-1;y++){

if (location[y]!=null){

location[y].inquire();

}

}

}

public product releaseProduct(){

int x = location.length;
product z;
z = null;

for(int y=0;y<x;y++){

if (location[y]!=null){

z = location[y];
location[y]=null;
break;

}

else {

z = null;

}

}
return z;

}

}

The wallet object

public class wallet{

public double money;

wallet(double m){

money = m;

}

public void balance(){

System.out.println(money);

}

}

The cashier object

public class cashier{

public shoppingCart leftHand;
public product rightHand;

cashier(){

}

public void getCart(counter c){

leftHand=c.cartRail;

}

public void speak(String phrase){

System.out.println(phrase+" (cashier)");

}

public void smile(){

System.out.println(":)");

}

public void getProduct(){

rightHand=leftHand.releaseProduct();

}

public void closeTransaction(cashRegister c,wallet w){

w.money = w.money - c.total;

}

}

The counter object

public class counter{

public shoppingCart cartRail;

counter(){

cartRail = new shoppingCart();

}

public void getCart(shoppingCart s){

cartRail = s;

}

}

The cashRegister object

public class cashRegister{

public double total;

cashRegister(){

total=0;

}

public void lcdDisplay(){

System.out.println(""+ total+ " (lcd display)");

}

public void accumulate(product p){

total = total + p.price;
System.out.println("beep!!! (cash register)");
System.out.println();

}

}

The PinoyTechZone.Com
Copyright 2002-2003
All rights Reserved