Reference no: EM132260708
All televisions have basic functionality to turn on and off, set the channel and volume. When paired to a TV, the remote control has buttons which invoke this functionality to operate the TV.
For this assignment, you will individually develop the Television and RemoteControl classes. You will demonstrate their functionality through a simple menu via the console in the TVApplication class.
Methodology
You will develop three classes with the following instance variables and methods
• Television class
• Stores instance variables for power, channel, maxChannel and volume (all private)
• maxChannel is final
• power has get/set methods
• channel has get/set methods. The set method ensures the television's channel stays between 1 and maxChannel at all times
• volume has a get method
• volume has a private set method. The set method ensures volume percentage stays between 0 and 100 at all times
• Has a volumeDown() method which decrements volume percentage by one
• Has a volumeUp() method which increments volume percentage by one
• maxChannel has a get method but no set method
• Constructors set volume to 0 and channel to 1
• Default constructor Television() sets maxChannel to 10
• Constructor Television(int max) sets maxChannel to max. If max is less than 2 then maxChannel is set to the value 10.
• toString method returns a string representation of a TV object.
Note: No other methods/instance variables are to be defined
Three examples of string representations of a Television object (i.e. toString method should return a string representation as follow):
[Television is: on? NO. CHANNEL: 1/10. VOLUME: 0% (muted)]
[Television is: on? YES. CHANNEL: 2/10. VOLUME: 50%]
[Television is: on? NO. CHANNEL: 2/10. VOLUME: 100%]
• RemoteControl class
• Maintains a Television instance variable with get and set methods
• Has a single constructor which takes as input a Televisionobject
• Has the powerButton() method to switch the TV on and off
• When the TV is switched on, the method ochannelDownButton() decreases the channel. If at 1, the channel is changed to maxChannel
o channelUpButton() increases the channel. If at maxChannel, the channel is changed to 1.
o volumeUpByHalf() increases the volume by 50% ovolumeDownByHalf() decreases the volume by 50%
Note: No other methods/instance variables are to be defined
TVApplication class has a single main method which instantiates a RemoteControl object. The user may repeatedly press buttons on the remote until they decide to stop watching TV. Use the Scanner class to read in a number from the console corresponding to a button on the remote.
Program Interaction
Sample interaction with the TVApplication main method.
[Television is: on? NO. CHANNEL: 1/10. VOLUME: 0% (muted)]
Press a Button on the Remote Control
1. Power 2. Volume Up by 50% 3. Volume Down by 50% 4. Channel Up 5. Channel Down 6. Go outside 2
Volume Up by 50% Button Pressed
[Television is: on? NO. CHANNEL: 1/10. VOLUME: 0% (muted)]
Press a Button on the Remote Control
1. Power 2. Volume Up by 50% 3. Volume Down by 50% 4. Channel Up 5. Channel Down 6. Go outside 1
Power Button Pressed
[Television is: on? YES. CHANNEL: 1/10. VOLUME: 0% (muted)]
Press a Button on the Remote Control
1. Power 2. Volume Up by 50% 3. Volume Down by 50% 4. Channel Up 5. Channel Down 6. Go outside 2
Volume Up by 50% Button Pressed
[Television is: on? YES. CHANNEL: 1/10. VOLUME: 50%]
Press a Button on the Remote Control
1. Power 2. Volume Up by 50% 3. Volume Down by 50% 4. Channel Up 5. Channel Down 6. Go outside 4
Channel Up Button Pressed
[Television is: on? YES. CHANNEL: 10/10. VOLUME: 50%]
Press a Button on the Remote Control
1. Power 2. Volume Up by 50% 3. Volume Down by 50% 4. Channel Up 5. Channel Down 6. Go outside 5
Channel Down Button Pressed
[Television is: on? YES. CHANNEL: 1/10. VOLUME: 50%]
Press a Button on the Remote Control
1. Power 2. Volume Up by 50% 3. Volume Down by 50% 4. Channel Up 5. Channel Down 6. Go outside 5
Channel Down Button Pressed
[Television is: on? YES. CHANNEL: 2/10. VOLUME: 50%]
Press a Button on the Remote Control
1. Power 2. Volume Up by 50% 3. Volume Down by 50% 4. Channel Up 5. Channel Down 6. Stop watching TV and go outside6