Create the class TV with the following UML.
Class TV contains the following data members:
- private channel: int between 0 and 99
- private volumeLevel: int between 0 and 8
- private on: boolean if on is true then TV is On, if on is false then its Off
Uml class diagram:
Tv |
-volumeLevel: int -channel: int -on: boolean |
+ turnOn(): void + turnOff():void + volumeLevelUp(int vol):void + volumeLevelDown(int vol):void + channelUp(int ch):void + channelDown(int ch):void + toString():String |
Class TV contains the following methods:
- public void turnOn(); Sets the variable on to true.
- public void turnOff(); Sets the variable on to false.
- public void volumeLevelUp(int vol); Increases volumeLevel by vol amount. However, volumeLevel must always be between 0 -8 for example, if volumeLevel is 5 and you called volumeLevelUp(3) then new volumeLevel Should be 5+3 = 8. (But volumeLevel must not exceed 8)
- public void volumeLevelDown(int vol); Decreases volumeLevel by vol amount. However, volumeLevel must always be between 0 -8. for example, if volumeLevel is 5 and you called volumeLevelDown(3) then new volumeLevel Should be 5-3 = 2. (But volumeLevel must not go below zero)
- public void channelUp(int ch); Increases channel number by ch. However, channel number must be between 0 – 99 (i.e. if channel is 90 and you go up 15 channels your new channel should be 5)
- public void channelDown(int ch); Decreases channel number by ch. However, channel number must be between 0 – 99 (i.e. if channel is 10 and you go down 15 channels your new channel should be 95)
- public String toString(); Returns all current information of the TV as a String. IF the TV is on it should return a string indicating TV is on in addition to volume and channel information. IF TV is off, it should return a message saying that. An example of the returned string is given below.
TV is on and current channel is 5 and current volume level is 8.
Create a class testTV that will do the following:
Declare an object tv1 of the class TV, then display the following menu:
These are your choices:
1)Turn TV On 2)Turn TV Off 3)Channel Up 4)Channel Down 5)Increase Volume 6)Decrease Volume 7)Exit
Enter your choice :>
Then chose the following options(after each option is performd, you must print the status of the TV):
- Turn on TV
- Channel up by 50
- Channel up by 60
- Increase volume by 4
- Increase volume by 7
- Decrease volume by 3
- Channel down by 90
- Turn off TV
Feel free to add your own tests. (Note that java always initializes your int data members to 0, so the value of the channel and volumeLevel when you create the TV object is 0)
Sample Run
These are your choices:
1)Turn TV On 2)Turn TV Off 3)Channel Up 4)Channel Down 5)Increase Volume 6)Decrease Volume 7)Exit
Enter your choice :> 1
TV is On and current channel is 0 and volume level is 0 These are your choices:
1)Turn TV On 2)Turn TV Off 3)Channel Up 4)Channel Down 5)Increase Volume 6)Decrease Volume 7)Exit
Enter your choice :> 3
How many channels up? :>50
TV is On and current channel is 50 and volume level is 0 These are your choices:
1)Turn TV On 2)Turn TV Off 3)Channel Up 4)Channel Down 5)Increase Volume 6)Decrease Volume 7)Exit
Enter your choice :> 3
How many channels up? :>60
TV is On and current channel is 10 and volume level is 0
These are your choices:
1)Turn TV On 2)Turn TV Off 3)Channel Up 4)Channel Down 5)Increase Volume 6)Decrease Volume 7)Exit
Enter your choice :> 5
How much you like to increase? 4
TV is On and current channel is 10 and volume level is 4
These are your choices:
1)Turn TV On 2)Turn TV Off 3)Channel Up 4)Channel Down 5)Increase Volume 6)Decrease Volume 7)Exit
Enter your choice :> 5
How much you like to increase? 7
TV is On and current channel is 10 and volume level is 8
These are your choices:
1)Turn TV On 2)Turn TV Off 3)Channel Up 4)Channel Down 5)Increase Volume 6)Decrease Volume 7)Exit
Enter your choice :> 6
How much you like to decrease? 3
TV is On and current channel is 10 and volume level is 5
These are your choices:
1)Turn TV On 2)Turn TV Off 3)Channel Up 4)Channel Down 5)Increase Volume 6)Decrease Volume 7)Exit
Enter your choice :> 4
How many channels down? :>90
TV is On and current channel is 20 and volume level is 5
These are your choices:
1)Turn TV On 2)Turn TV Off 3)Channel Up 4)Channel Down 5)Increase Volume 6)Decrease Volume 7)Exit
Enter your choice :> 2
TV is Off
These are your choices:
1)Turn TV On 2)Turn TV Off 3)Channel Up 4)Channel Down 5)Increase Volume 6)Decrease Volume 7)Exit
Enter your choice :> 7
Class Tv:
TestTv:
need an explanation for this answer? contact us directly to get an explanation for this answer