Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1.  
  2. public class Television
  3. {
  4. private boolean power;
  5. private int channel;
  6. private final int maxChannel;
  7. private int volume;
  8.  
  9. //public String toString()
  10. //{
  11. // return "[Television is: on? " +this.power+ ". CHANNEL: " +channel+ "/" +maxChannel+ ". VOLUME: " +volume+ "%" + "]";
  12. //}
  13.  
  14. public Television()
  15. {
  16. volume = 0;
  17. channel = 1;
  18. maxChannel = 10;
  19. }
  20.  
  21. public Television(int max)
  22. {
  23. volume = 0;
  24. channel = 1;
  25. maxChannel = max;
  26.  
  27. if (max < 2)
  28. {
  29. maxChannel = 10;
  30. }
  31. }
  32.  
  33. public boolean getPower()
  34. {
  35. return power;
  36. }
  37.  
  38. public void setPower(boolean powerInput)
  39. {
  40. power = powerInput;
  41. }
  42.  
  43. public int getChannel()
  44. {
  45. return channel;
  46. }
  47.  
  48. public void setChannel(int channelInput)
  49. {
  50. if (channel <= maxChannel)
  51. {
  52. channel = channelInput;
  53. }
  54. }
  55.  
  56. public int getVolume()
  57. {
  58. return volume;
  59. }
  60.  
  61. private void setVolume(int volumeInput )
  62. {
  63. if (volume >= 0 && volume <= 100)
  64. {
  65. volume = volumeInput;
  66. }
  67. }
  68.  
  69. public void volumeDown()
  70. {
  71. setVolume(volume -1);
  72. }
  73.  
  74. public void volumeUp()
  75. {
  76. setVolume(volume +1);
  77. }
  78.  
  79. public int getMaxChannel()
  80. {
  81. return maxChannel;
  82. }
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement