Guest User

Untitled

a guest
Feb 20th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package myPackage;
  2.  
  3. public class ChocolateBoiler {
  4.     private boolean empty;
  5.     private boolean boiled;
  6.     private static ChocolateBoiler uniqueInstance;
  7.     private ChocolateBoiler(){
  8.         empty = true;
  9.         boiled = false;
  10.     }
  11.    
  12.     public static ChocolateBoiler getInstance(){
  13.         if (uniqueInstance == null)
  14.             uniqueInstance = new ChocolateBoiler();
  15.        
  16.         return uniqueInstance;
  17.     }
  18.    
  19.     public boolean isEmpty(){
  20.         return empty;
  21.     }
  22.    
  23.     public boolean isBoiled(){
  24.         return boiled;
  25.     }
  26.    
  27.     public void fill(){
  28.         if (isEmpty())
  29.         {
  30.             empty = false;
  31.             boiled = false;
  32.         }
  33.     }
  34.    
  35.     public void drain(){
  36.         if (!isEmpty() && isBoiled())
  37.             empty = true;
  38.     }
  39.    
  40.     public void boil(){
  41.         if (!isEmpty() && !isBoiled())
  42.             boiled = true;
  43.     }
  44. }
  45.  
  46.  
  47. package myPackage;
  48.  
  49. public class Driver {
  50.  
  51.     /**
  52.      * @param args
  53.      */
  54.     public static void main(String[] args) {
  55.         // TODO Auto-generated method stub
  56. ChocolateBoiler cb = ChocolateBoiler.getInstance();
  57. cb.fill();
  58. cb.drain();
  59. System.out.println("cb mem address = " + cb.toString());
  60.  
  61. ChocolateBoiler cb2 = ChocolateBoiler.getInstance();
  62. System.out.println("cb2 = " + cb.toString());
  63.     }
  64.  
  65. }
Add Comment
Please, Sign In to add comment