EXCELLENT!!! WE'RE NOT WORTHY!

Panos


From: Greg Nudelman <[EMAIL PROTECTED]>
Reply-To: "jdjlist" <[EMAIL PROTECTED]>
To: "jdjlist" <[EMAIL PROTECTED]>
Subject: [jdjlist] RE: Hospital Tea... a Java example (crisies only)
Date: Fri, 30 May 2003 17:09:35 -0700

We're Not Worthy! We're Not Worthy!
:-)

Happy Friday!

Greg

-----Original Message-----
From: Jason Bell [mailto:[EMAIL PROTECTED]
Sent: Friday, May 30, 2003 4:58 PM
To: jdjlist
Subject: [jdjlist] Hospital Tea... a Java example (crisies only)


Dear all.


In following from my wife's email (and yes it was my wife really, not me
messing about). Here's the code for the Hospital Tea. In fact it's a
generic tea bean (not coffee), via a factory pattern. Works for me fine and
dandy-o. And it's javadoc'd as well :)


CupOfTea.java

package com.jaseb.tea;
import java.util.ArrayList;

import java.util.List;

/**
* @author Jason Bell
*/

public class CupOfTea {
    protected int sugars = 0;
    protected int secondsTeaBagLeftInCup = 0;
    protected String amountOfMilk = "";
/**
* <p>Some people like the milk first, before they stick the teabag in and
then add the sugar...</p>
*/
    protected List itemOrder = new ArrayList();
/**
* <p>Returns the amount of milk poured into the cup.</p>
* @return String
*/
    public String getAmountOfMilk() {
        return amountOfMilk;
    }
/**
* <p>Number of seconds that the teabag is left in the cup.</p>
* @return int
*/
    public int getSecondsTeaBagLeftInCup() {
        return secondsTeaBagLeftInCup;
    }
/**
* <p>Returns the number of teaspoons of sugar are in the cup.</p>
* @return int
*/
    public int getSugars() {
        return sugars;
    }
/**
* Sets the amountOfMilk.
* @param amountOfMilk The amountOfMilk to set
*/
    public void setAmountOfMilk(String amountOfMilk) {
        this.amountOfMilk = amountOfMilk;
    }
/**
* Sets the secondsTeaBagLeftInCup.
* @param secondsTeaBagLeftInCup The secondsTeaBagLeftInCup to set
*/
    public void setSecondsTeaBagLeftInCup(int secondsTeaBagLeftInCup) {
        this.secondsTeaBagLeftInCup = secondsTeaBagLeftInCup;
    }
/**
* Sets the sugars.
* @param sugars The sugars to set
*/
       public void setSugars(int sugars) {
        this.sugars = sugars;
    }
/**
* @return List
*/
    public List getItemOrder() {
        return itemOrder;
    }
/**
* Sets the itemOrder.
* @param itemOrder The itemOrder to set
*/
    public void setItemOrder(List itemOrder) {
       this.itemOrder = itemOrder;
    }
}

CupOfTeaMngr.java

package com.jaseb.tea;

/**

* @author Jason Bell

*/

public abstract class CupOfTeaMngr {
private static CupOfTeaMngr instance;
private static synchronized void createInstance() {
    if (instance == null) {
        Class mgr = null;
        CupOfTeaMngr um = null;
        try {
            String classname = "com.jaseb.tea.StreamCupOfTeaMngr";
            mgr =
            Thread.currentThread().getContextClassLoader().loadClass(
            classname);
        } catch (ClassNotFoundException e) {
        e.printStackTrace();
            }
            try {
                um = (CupOfTeaMngr) mgr.newInstance();
                instance = um;
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
    public static CupOfTeaMngr getInstance() {
    if (instance == null) {
        createInstance();
    }
        return instance;
    }
    protected CupOfTeaMngr() {
    }
    public abstract void makeTea(CupOfTea tea) throws Exception;
}

StreamCupOfTeaMngr.java

package com.jaseb.tea;

/**

* @author Jason Bell

*/

public class StreamCupOfTeaMngr extends CupOfTeaMngr{
    public void makeTea(CupOfTea tea){
        System.out.println("Making tea....");
        String strength = "normal";
        if(tea.getSecondsTeaBagLeftInCup() <= 1){
            strength = "hosptial";
        } else if(tea.getSecondsTeaBagLeftInCup() > 1 &&
                        tea.getSecondsTeaBagLeftInCup() < 15) {
            strength = "normal";
        } else if(tea.getSecondsTeaBagLeftInCup() > 16){
            strength = "strong";
        }
        System.out.println("Strength is " + strength);
        System.out.println("Adding milk " + tea.getAmountOfMilk());
        System.out.println("Adding " + tea.getSugars() + " sugars.");
    }
}

MakeACupOfTea.java

package com.jaseb.tea;

/**

* @author Jason Bell

*/

public class MakeACupOfTea {
    public MakeACupOfTea() {
        CupOfTea prepareCup = new CupOfTea();
        prepareCup.setSecondsTeaBagLeftInCup(1);
        prepareCup.setSugars(2);
        prepareCup.setAmountOfMilk(" lots and lots ");

        CupOfTeaMngr thisCup = CupOfTeaMngr.getInstance();
        try {
            thisCup.makeTea(prepareCup);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args){
        MakeACupOfTea tea = new MakeACupOfTea();
    }
}


--- You are currently subscribed to jdjlist as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] http://www.sys-con.com/fusetalk



---
You are currently subscribed to jdjlist as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
http://www.sys-con.com/fusetalk

_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail



--- You are currently subscribed to jdjlist as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] http://www.sys-con.com/fusetalk

Reply via email to