Advertisement
vvccs

EXP3

Apr 13th, 2024 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MultimediaDevice
  4. {
  5. public interface IPowerControl
  6. {
  7. void TurnOn();
  8. void TurnOff();
  9. }
  10.  
  11. public interface IVolumeControl
  12. {
  13. void IncreaseVolume();
  14. void DecreaseVolume();
  15. }
  16.  
  17. public interface IChannelControl
  18. {
  19. void NextChannel();
  20. void PreviousChannel();
  21. }
  22.  
  23. public class Television : IPowerControl, IVolumeControl, IChannelControl
  24. {
  25. private bool _isOn = false;
  26. private int _volume = 0;
  27. private int _currentChannel = 1;
  28.  
  29. public void TurnOn()
  30. {
  31. _isOn = true;
  32. Console.WriteLine("The Television is ON");
  33. }
  34.  
  35. public void TurnOff()
  36. {
  37. _isOn = false;
  38. Console.WriteLine("The Television is OFF");
  39. }
  40.  
  41. public void IncreaseVolume()
  42. {
  43. if (_isOn)
  44. {
  45. _volume++;
  46. Console.WriteLine("Volume increased to {0}", _volume);
  47. }
  48. else
  49. {
  50. Console.WriteLine("Please turn on the television first.");
  51. }
  52. }
  53.  
  54. public void DecreaseVolume()
  55. {
  56. if (_isOn)
  57. {
  58. if (_volume > 0)
  59. {
  60. _volume--;
  61. Console.WriteLine("Volume increased to {0}", _volume);
  62. }
  63. else
  64. {
  65. Console.WriteLine("Volume is already at minimum.");
  66. }
  67. }
  68. else
  69. {
  70. Console.WriteLine("Please turn on the television first.");
  71. }
  72. }
  73.  
  74. public void NextChannel()
  75. {
  76. if (_isOn)
  77. {
  78. _currentChannel++;
  79. Console.WriteLine("Switched to channel {0}", _currentChannel);
  80. }
  81. else
  82. {
  83. Console.WriteLine("Please turn on the television first.");
  84. }
  85. }
  86.  
  87. public void PreviousChannel()
  88. {
  89. if (_isOn)
  90. {
  91. if (_currentChannel > 1)
  92. {
  93. _currentChannel--;
  94. Console.WriteLine("Switched to channel {0}", _currentChannel);
  95. }
  96. else
  97. {
  98. Console.WriteLine("You are already on the first channel.");
  99. }
  100. }
  101. else
  102. {
  103. Console.WriteLine("Please turn on the television first.");
  104. }
  105. }
  106. }
  107.  
  108. class Program
  109. {
  110. static void Main(string[] args)
  111. {
  112. Television tv = new Television();
  113.  
  114. Console.WriteLine("TV is OFF \n");
  115.  
  116. int choice;
  117. do
  118. {
  119. Console.WriteLine("\nChoose the function to use: ");
  120. Console.WriteLine("1. Power Control");
  121. Console.WriteLine("2. Volume Control");
  122. Console.WriteLine("3. Channel Control");
  123. Console.WriteLine("4. Exit\n");
  124.  
  125. choice = int.Parse(Console.ReadLine());
  126.  
  127. switch (choice)
  128. {
  129. case 1:
  130. Console.WriteLine("1. Turn On\n2. Turn Off\n");
  131. int powerChoice = int.Parse(Console.ReadLine());
  132. if (powerChoice == 1)
  133. {
  134. tv.TurnOn();
  135. }
  136. else if (powerChoice == 2)
  137. {
  138. tv.TurnOff();
  139. }
  140. break;
  141.  
  142. case 2:
  143. Console.WriteLine("1. Increase Volume\n2. Decrease Volume\n");
  144. int volumeChoice = int.Parse(Console.ReadLine());
  145. if (volumeChoice == 1)
  146. {
  147. tv.IncreaseVolume();
  148. }
  149. else if (volumeChoice == 2)
  150. {
  151. tv.DecreaseVolume();
  152. }
  153. break;
  154.  
  155. case 3:
  156. Console.WriteLine("1. Next Channel\n2. Previous Channel\n");
  157. int channelChoice = int.Parse(Console.ReadLine());
  158. if (channelChoice == 1)
  159. {
  160. tv.NextChannel();
  161. }
  162. else if (channelChoice == 2)
  163. {
  164. tv.PreviousChannel();
  165. }
  166. break;
  167.  
  168. case 4:
  169. Console.WriteLine("Exiting...");
  170. break;
  171.  
  172. default:
  173. Console.WriteLine("Invalid choice! Please choose again.");
  174. break;
  175. }
  176.  
  177. } while (choice != 4);
  178. }
  179. }
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement