Advertisement
AviEzerzer

Disco

Dec 5th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.78 KB | None | 0 0
  1. /**
  2.  * Disco class aims to represent a array of 4 bulbs.
  3.  *
  4.  * @author (Avi Ezerzer)
  5.  * @version (3.25 12/05/2014)
  6.  */
  7. public class Disco
  8. {
  9.     //declare all bulbs.
  10.     private LightBulb _bulb1;
  11.     private LightBulb _bulb2;
  12.     private LightBulb _bulb3;
  13.     private LightBulb _bulb4;
  14.    
  15.     /**
  16.      * construct a disco instance comprised of 4 bulbs.
  17.      */
  18.     public Disco(LightBulb b1, LightBulb b2, LightBulb b3, LightBulb b4)
  19.     {
  20.         _bulb1 = b1;
  21.         _bulb2 = b2;
  22.         _bulb3 = b3;
  23.         _bulb4 = b4;
  24.     }
  25.     /**
  26.      * Returns the first LightBulb
  27.      */
  28.     public LightBulb getFirstBulb()
  29.     {
  30.         return _bulb1;
  31.     }
  32.     /**
  33.      * Returns the first LightBulb
  34.      */
  35.     public LightBulb getSecondBulb()
  36.     {
  37.         return _bulb2;
  38.     }
  39.     /**
  40.      * Returns the first LightBulb
  41.      */
  42.     public LightBulb getThirdBulb()
  43.     {
  44.         return _bulb3;
  45.     }
  46.     /**
  47.      * Returns the first LightBulb
  48.      */
  49.     public LightBulb getFourthBulb()
  50.     {
  51.         return _bulb4;
  52.     }
  53.     //comment by cat walking on keyboard nhjjjjjjjjjjjjmmmmmmmmmmmmmmmmmjhnuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
  54.     /**
  55.      * alters the switch state of the lightbulb.
  56.      * @param num - number of the bulb to be switched to counterstate.
  57.      */
  58.     public void switchBulb(int num)
  59.     {
  60.         if (num == 1)
  61.             _bulb1.switchLight();
  62.         else if (num == 2)
  63.             _bulb2.switchLight();
  64.         else if (num == 3)
  65.             _bulb3.switchLight();
  66.         else if (num == 4)
  67.             _bulb4.switchLight();
  68.     }
  69.     /**
  70.      * Turn all the bulbs on
  71.      */
  72.     public void turnAllOn()
  73.     {
  74.         _bulb1.lightOn();
  75.         _bulb2.lightOn();
  76.         _bulb3.lightOn();
  77.         _bulb4.lightOn();
  78.     }
  79.     /**
  80.      * Turn all the bulbs off
  81.      */
  82.     public void turnAllOff()
  83.     {
  84.         _bulb1.lightOff();
  85.         _bulb2.lightOff();
  86.         _bulb3.lightOff();
  87.         _bulb4.lightOff();
  88.     }
  89.     /**
  90.      * checks if all four bulbs are on
  91.      */
  92.     public boolean areAllOn()
  93.     {
  94.         return (_bulb1.isSwitchedOn() && _bulb2.isSwitchedOn() &&_bulb3.isSwitchedOn() &&_bulb4.isSwitchedOn());  
  95.     }
  96.      /**
  97.      * checks if all four bulbs are off
  98.      */
  99.     public boolean areAllOff()
  100.     {
  101.         return (!_bulb1.isSwitchedOn() && !_bulb2.isSwitchedOn() && !_bulb3.isSwitchedOn() && !_bulb4.isSwitchedOn());      
  102.     }
  103.     /**
  104.      * checks if all bulbs match in color.
  105.      */
  106.     public boolean allSameColor()
  107.     {
  108.         return (_bulb1.getColor().equals(_bulb2.getColor()) &&
  109.                 _bulb1.getColor().equals(_bulb3.getColor()) &&  
  110.                 _bulb1.getColor().equals(_bulb4.getColor()));  
  111.                  
  112.     }
  113.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement