This assignment focuses on the development of Methods. Follow the directions bel
ID: 3580687 • Letter: T
Question
This assignment focuses on the development of Methods.
Follow the directions below to complete this assignment. Note: I am very explicit in what I expect you to do. The methods are well defined and are to be followed!!!
Java TV Controller
Everyone is familiar with a television. You are going to create a program that mimics the controlling of the operation of a television remote control. Think about a television in general. It has some basic controls. There is a control to turn the power on and off, change the channel, and for the volume. At any point in time, the television’s state can be described by how these controls are set.
You will have to create the following attributes:
powerOn // holds the value true if the power is on, and false if the power is off.
channel // holds the value of the station that the television is showing. The range of this value is 2 through 99. Set its initial value to 3
volume // holds a number value representing the loudness (0 being no sound). The range of this value is 0 to 10. Set its initial value to 5
mode // sets the input mode of the TV. Set its initial value to TV
Input: Accept the full command (i.e., Turn On). Be able to handle case insensitive input and space characters.
Output: For all of your output messages other than the Banner message, use the DisplayMessage method only!! Upon starting your program, you will display the Banner message (invoke the Banner method). When you Exit the program, you will display the message “Thank you for using the Java Remote Controller”
For the main body of your program, you will then ask the user for input and loop continuously looking for further user input until Exit is entered. Upon entering one of the following options, you will call the respective method to perform the operations.
The User Inputs are:
Turn On – turns on the TV
Turn Off – turns off the TV
Volume Up – turns up the volume by 1
Volume Down – turns down the volume by 1.
Channel Up – increments the channel by 1.
Channel Down – decrements the channel by 1.
Mode TV – sets the mode selection to TV
Mode DVD – sets the mode selection to DVD
Exit – turns off the remote control and exits the program.
You will have to write methods named:
TurnOn:
Accepts the powerOn parameter to allow for determining if the powerOn parameter is true or false
Return value is updated powerOn attribute
If the powerOn value is already true
Display a message “TV already on”
If the powerOn value is false
Sets the powerOn attribute value to true.
Display a message “TV On, Your Channel is xxx and the Volume is xxx”
TurnOff:
Accepts the powerOn parameter to allow for determining if the powerOn parameter is true or false
Return value is updated powerOn attribute
Sets the powerOn attribute value to false
Display a message “TV is now off”
If the powerOn value is already false,
DIsplay a message “TV already off”
VolumeUp:
Accepts the powerOn parameter to allow for determining if the powerOn parameter is true or false and the volume parameter
Return value is updated volume attribute
If the powerOn parameter is false
Display a message “TV is off”
Test the value of the volume attribute - You cannot increment the volume attribute greater than 10.
If the volume value is less than 10, increment the volume value by 1.
If the volume attribute is 10, display “Maximum Volume”
VolumeDown:
Accepts the powerOn parameter to allow for determining if the powerOn parameter is trueor false and the volume parameter
Return value is updated volume attribute
If the powerOn parameter is false
Display a message “TV is off”
If the powerOn parameter is true, test the value of the volume attribute - You cannot decrement the volume attribute lower than 0.
If the value is greater than 0, decrement the volume attribute value by 1
If the value is 0, display “Sound Muted”
ChannelUp
Accepts the powerOn parameter to allow for determining if the powerOn parameter is true or falseand the channel parameter
Return value is the updated channel parameter
If the powerOn parameter is false
Display a message “TV is off”
If the powerOn parameter is true, test the value of the channel attribute – the channel range is from 2 through 99.
If the channel value is less than 99, increment that channel value by 1
If the channel value is 99, set the channel value to 2
Display the current channel using the display method “Channel x”
ChannelDown
Accepts the powerOn parameter to allow for determining if the powerOn parameter is true or falseand the channel parameter
Return value is the updated channel parameter
If the powerOn parameter is false
Display a message “TV is off”
If the powerOn parameter is true, test the value of the channel attribute – the channel range is from 2 through 99.
If the channel value is less than 99, increment that channel value by 1
If the channel value is 99, set the channel value to 2
Display the current channel using the display method “Channel x”
SetModeTV:
Accepts the powerOn parameter to allow for determining if the powerOn parameter is true or false
Return is the updated mode value
If the powerOn parameter is false
Display a message “TV is off”
If the powerOn parameter is true
display “TV Mode”
Return mode set to TV
SetModeDVD:
Accepts the powerOn parameter to allow for determining if the powerOn parameter is true or false
Return is the updated mode value
If the powerOn parameter is false
Display a message “TV is off”
If the powerOn parameter is true
display “DVD Mode”
Return mode set to DVD
// methods that I’m providing
/*
Common Display methods
*/
public static void DisplayMessage(String msg)
{
System.out.println(msg);
} // end method
/*
Display banner
*/
public static void Banner()
{
System.out.println("Welcome to your Java TV Remote Control");
System.out.println("Please enter your selection");
System.out.println("Turn On - turns on your TV");
System.out.println("Turn Off - turns off your TV");
System.out.println("Volume Up - turns up the volume");
System.out.println("Volume Down - turn down the volume");
System.out.println("Channel Up - increments the channel");
System.out.println("Channel Down - decrements the channel");
System.out.println("Mode TV – set TV mode");
System.out.println("Mode DVD – set DVD mode");
System.out.println();
System.out.println("Please enter your selection");
} // end method
Explanation / Answer
import java.util.*;
//Class TV Controller defined
class TVController
{
//Data member of the class
static boolean powerOn;
static int channel = 3;
static int volume = 5;
static String mode = "TV";
//Method to turn on the TV
static boolean TurnOn()
{
//Checks the power status
if(powerOn)
DisplayMessage("TV already on");
//If it is off set it to on and display the current channel and volume
else
{
powerOn = true;
System.out.println("TV On, Your Channel is " + channel + " and the Volume is " + volume);
}
//Return power status
return powerOn;
}
//Method to turn off the TV
static boolean TurnOff()
{
//If it is on set it to off
if(powerOn)
{
powerOn = false;
DisplayMessage("TV is now off");
}
//If it is already off
else
DisplayMessage("TV already off");
//Return power status
return powerOn;
}
//Method to increase the volume by 1
static int VolumeUp()
{
//If power is on
if(powerOn)
//If volume is maximum
if(volume == 10)
DisplayMessage("Maximum Volume");
//If volume is not maximum increase the volume by 1
else
volume++;
//If tv is off
else
DisplayMessage("TV is off");
//Return volume
return volume;
}
//Method to decrease the volume by 1
static int VolumeDown()
{
//If power is on
if(powerOn)
{
//If volume is minimum
if(volume == 0)
DisplayMessage("Sound Muted");
//If volume is not minimum decrease the volume by 1
else
volume--;
}
//If tv is off
else
{
DisplayMessage("TV is off");
}
//Return volume
return volume;
}
//Method to increase the channel by 1
static int ChannelUp()
{
//If power is on
if(powerOn)
{
//If channel is maximum set the channel to 2
if(channel == 99)
channel = 2;
//If channel is not maximum increase the channel by 1
else
channel++;
}
//If tv is off
else
{
DisplayMessage("TV is off");
}
//Return channel
return channel;
}
//Method to decrease the channel by 1
static int ChannelDown()
{
//If power is on
if(powerOn)
{
//If channel is minimum set the channel to 99
if(channel == 2)
channel = 99;
//If channel is not minimum decrease the channel by 1
else
channel--;
}
//If tv is off
else
{
DisplayMessage("TV is off");
}
//Return channel
return channel;
}
//Set the TV Mode
static String setModeTV()
{
//If power is on set the mode to TV
if(powerOn)
{
mode = "TV";
DisplayMessage("TV mode");
}
//If tv is off
else
DisplayMessage("TV is off");
//Return mode
return mode;
}
//Set the DVD Mode
static String setModeDVD()
{
//If power is on set the mode to DVD
if(powerOn)
{
mode = "DVD";
DisplayMessage("DVD mode");
}
//If tv is off
else
DisplayMessage("TV is off");
//Return mode
return mode;
}
// methods that I’m providing
/*
Common Display methods
*/
public static void DisplayMessage(String msg)
{
System.out.println(msg);
} // end method
/*
Display banner
*/
public static void Banner()
{
System.out.println(" Welcome to your Java TV Remote Control");
System.out.println("Please enter your selection");
System.out.println("1) Turn On - turns on your TV");
System.out.println("2) Turn Off - turns off your TV");
System.out.println("3) Volume Up - turns up the volume");
System.out.println("4) Volume Down - turn down the volume");
System.out.println("5) Channel Up - increments the channel");
System.out.println("6) Channel Down - decrements the channel");
System.out.println("7) Mode TV – set TV mode");
System.out.println("8) Mode DVD – set DVD mode");
System.out.println("9) Exit");
System.out.println();
System.out.println("Please enter your selection");
} // end method
public static void main(String ss[])
{
int ch;
//Scanner class to accept user choice
Scanner sc = new Scanner(System.in);
do
{
//Displays the menu
Banner();
//Accept user choice
ch = sc.nextInt();
switch(ch)
{
case 1:
TurnOn();
break;
case 2:
TurnOff();
break;
case 3:
DisplayMessage("Volume: " + String.valueOf(VolumeUp()));
break;
case 4:
DisplayMessage("Volume: " + String.valueOf(VolumeDown()));
break;
case 5:
DisplayMessage("Channel: " + String.valueOf(ChannelUp()));
break;
case 6:
DisplayMessage("Channel: " + String.valueOf(ChannelDown()));
break;
case 7:
setModeTV();
break;
case 8:
setModeDVD();
break;
case 9:
System.exit(0);
break;
default:
System.out.println("ERROR: Invalid Choice! Re - Enter: ");
}
}while(true);
}
}
Ouput:
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
2
TV already off
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
1
TV On, Your Channel is 3 and the Volume is 5
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
6
Channel: 2
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
6
Channel: 99
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
3
Volume: 6
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
3
Volume: 7
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
3
Volume: 8
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
3
Volume: 9
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
7
TV mode
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
8
DVD mode
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
4
Volume: 8
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
4
Volume: 7
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
4
Volume: 6
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
4
Volume: 5
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
5
Channel: 2
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
5
Channel: 3
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
5
Channel: 4
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
5
Channel: 5
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
3
Volume: 6
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
3
Volume: 7
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
3
Volume: 8
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
3
Volume: 9
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
3
Volume: 10
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
3
Maximum Volume
Volume: 10
Welcome to your Java TV Remote Control
Please enter your selection
1) Turn On - turns on your TV
2) Turn Off - turns off your TV
3) Volume Up - turns up the volume
4) Volume Down - turn down the volume
5) Channel Up - increments the channel
6) Channel Down - decrements the channel
7) Mode TV ? set TV mode
8) Mode DVD ? set DVD mode
9) Exit
Please enter your selection
9
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.