Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q2) Create the class TV with the following UML. Class TV contains the following data members: - private channel: int between 0 and 99 -

image text in transcribedimage text in transcribedimage text in transcribed

Q2) 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 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 08 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 08. 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 099 (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 099 (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 and volume level is These are your choices: 1)TurnTVOn5)IncreaseVolume2)TurnTVOff6)DecreaseVolume3)ChannelUp4)ChannelDown7)Exit Enter your choice :> 3 How many channels up? :>50 TV is On and current channel is 50 and volume level is 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 These are your choices: 1)TurnTVOn2)TurnTVOff3)ChannelUp4)ChannelDown 5) Increase Volume 6)Decrease Volume 7) Exit Enter your choice :> 5 How much you like to increase? 4 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 and volume level is These are your choices: 1)TurnTVOn5)IncreaseVolume2)TurnTVOff6)DecreaseVolume3)ChannelUp4)ChannelDown7)Exit Enter your choice :> 3 How many channels up? :>50 TV is On and current channel is 50 and volume level is 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 These are your choices: 1)TurnTVOn2)TurnTVOff3)ChannelUp4)ChannelDown 5) Increase Volume 6)Decrease Volume 7) Exit Enter your choice :> 5 How much you like to increase? 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

sharing of non-material benefits such as time and affection;

Answered: 1 week ago