Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package myPackage;
- public class ChocolateBoiler {
- private boolean empty;
- private boolean boiled;
- private static ChocolateBoiler uniqueInstance;
- private ChocolateBoiler(){
- empty = true;
- boiled = false;
- }
- public static ChocolateBoiler getInstance(){
- if (uniqueInstance == null)
- uniqueInstance = new ChocolateBoiler();
- return uniqueInstance;
- }
- public boolean isEmpty(){
- return empty;
- }
- public boolean isBoiled(){
- return boiled;
- }
- public void fill(){
- if (isEmpty())
- {
- empty = false;
- boiled = false;
- }
- }
- public void drain(){
- if (!isEmpty() && isBoiled())
- empty = true;
- }
- public void boil(){
- if (!isEmpty() && !isBoiled())
- boiled = true;
- }
- }
- package myPackage;
- public class Driver {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- ChocolateBoiler cb = ChocolateBoiler.getInstance();
- cb.fill();
- cb.drain();
- System.out.println("cb mem address = " + cb.toString());
- ChocolateBoiler cb2 = ChocolateBoiler.getInstance();
- System.out.println("cb2 = " + cb.toString());
- }
- }
Add Comment
Please, Sign In to add comment