Remote control

Report a typo

Suppose you are building a remote control application. It performs three commands: turning on the TV, changing the channel to a specific number, and turning off the TV. Use the command pattern to implement this application.

Use the following guidelines.

  • Don't change the provided code.
  • The first command to execute is to turn on the TV. The TurnOn command must print Turning on the TV.
  • Next, change channels to the inputs given by the user. The user must give only three inputs. The ChangeChannel command will print Channel was changed to X. X is the number given by the user.
  • The last command is to turn off the TV. The TurnOff command must print Turning off the TV.

Sample Input 1:

4 7 12

Sample Output 1:

Turning on the TV
Channel was changed to 4
Channel was changed to 7
Channel was changed to 12
Turning off the TV
Write a program in Java 17
import java.util.Scanner;

class Client {

public static void main(String[] args) {

Controller controller = new Controller();
TV tv = new TV();

int[] channelList = new int[3];

Scanner scanner = new Scanner(System.in);
for (int i = 0; i < 3; i++) {
channelList[i] = scanner.nextInt();
}

Command turnOnTV = new TurnOnCommand(tv);
/* write your code here */

Command changeChannel;
for (int i = 0; i < 3; i++) {
/* write your code here */
}

Command turnOffTV = new TurnOffCommand(tv);
/* write your code here */
}
}

class TV {

Channel channel;

void turnOn() {
System.out.println("Turning on the TV");
setChannel(new Channel(this, 0));
___

Create a free account to access the full topic