Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1.  
  2.  
  3. public class LightBulb
  4. {
  5. private RGBColor _color;
  6. private boolean _switchedOn;
  7.  
  8. public LightBulb(int red, int green, int blue)
  9. {
  10. _color = new RGBColor(red,green,blue);
  11. _switchedOn = false;
  12. }
  13.  
  14. public LightBulb(RGBColor color)
  15. {
  16. _color = new RGBColor(color);
  17. _switchedOn = false;
  18. }
  19.  
  20.  
  21. public LightBulb(LightBulb other)
  22. {
  23. _color = new RGBColor(other._color);
  24. _switchedOn = other._switchedOn;
  25. }
  26.  
  27. public RGBColor getColor()
  28. {
  29. return new RGBColor(_color);
  30. }
  31.  
  32. public void setColor(RGBColor color)
  33. {
  34. _color = new RGBColor(color);
  35. }
  36.  
  37. public boolean isSwitchedOn()
  38. {
  39. if(_switchedOn == true)
  40. return true;
  41. return false;
  42. }
  43.  
  44. public void switchLight()
  45. {
  46. if(_switchedOn == true)
  47. _switchedOn = false;
  48. else
  49. _switchedOn = true;
  50. }
  51.  
  52. public String toString()
  53. {
  54. String Light;
  55. if(_switchedOn == true)
  56. Light = "On";
  57. else Light = "Off";
  58. return _color + " " + Light;
  59. }
  60.  
  61.  
  62.  
  63.  
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement