Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace MultimediaDevice
- {
- public interface IPowerControl
- {
- void TurnOn();
- void TurnOff();
- }
- public interface IVolumeControl
- {
- void IncreaseVolume();
- void DecreaseVolume();
- }
- public interface IChannelControl
- {
- void NextChannel();
- void PreviousChannel();
- }
- public class Television : IPowerControl, IVolumeControl, IChannelControl
- {
- private bool _isOn = false;
- private int _volume = 0;
- private int _currentChannel = 1;
- public void TurnOn()
- {
- _isOn = true;
- Console.WriteLine("The Television is ON");
- }
- public void TurnOff()
- {
- _isOn = false;
- Console.WriteLine("The Television is OFF");
- }
- public void IncreaseVolume()
- {
- if (_isOn)
- {
- _volume++;
- Console.WriteLine("Volume increased to {0}", _volume);
- }
- else
- {
- Console.WriteLine("Please turn on the television first.");
- }
- }
- public void DecreaseVolume()
- {
- if (_isOn)
- {
- if (_volume > 0)
- {
- _volume--;
- Console.WriteLine("Volume increased to {0}", _volume);
- }
- else
- {
- Console.WriteLine("Volume is already at minimum.");
- }
- }
- else
- {
- Console.WriteLine("Please turn on the television first.");
- }
- }
- public void NextChannel()
- {
- if (_isOn)
- {
- _currentChannel++;
- Console.WriteLine("Switched to channel {0}", _currentChannel);
- }
- else
- {
- Console.WriteLine("Please turn on the television first.");
- }
- }
- public void PreviousChannel()
- {
- if (_isOn)
- {
- if (_currentChannel > 1)
- {
- _currentChannel--;
- Console.WriteLine("Switched to channel {0}", _currentChannel);
- }
- else
- {
- Console.WriteLine("You are already on the first channel.");
- }
- }
- else
- {
- Console.WriteLine("Please turn on the television first.");
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Television tv = new Television();
- Console.WriteLine("TV is OFF \n");
- int choice;
- do
- {
- Console.WriteLine("\nChoose the function to use: ");
- Console.WriteLine("1. Power Control");
- Console.WriteLine("2. Volume Control");
- Console.WriteLine("3. Channel Control");
- Console.WriteLine("4. Exit\n");
- choice = int.Parse(Console.ReadLine());
- switch (choice)
- {
- case 1:
- Console.WriteLine("1. Turn On\n2. Turn Off\n");
- int powerChoice = int.Parse(Console.ReadLine());
- if (powerChoice == 1)
- {
- tv.TurnOn();
- }
- else if (powerChoice == 2)
- {
- tv.TurnOff();
- }
- break;
- case 2:
- Console.WriteLine("1. Increase Volume\n2. Decrease Volume\n");
- int volumeChoice = int.Parse(Console.ReadLine());
- if (volumeChoice == 1)
- {
- tv.IncreaseVolume();
- }
- else if (volumeChoice == 2)
- {
- tv.DecreaseVolume();
- }
- break;
- case 3:
- Console.WriteLine("1. Next Channel\n2. Previous Channel\n");
- int channelChoice = int.Parse(Console.ReadLine());
- if (channelChoice == 1)
- {
- tv.NextChannel();
- }
- else if (channelChoice == 2)
- {
- tv.PreviousChannel();
- }
- break;
- case 4:
- Console.WriteLine("Exiting...");
- break;
- default:
- Console.WriteLine("Invalid choice! Please choose again.");
- break;
- }
- } while (choice != 4);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement