514,829 views
43 votes
43 votes
A video game controller contains the buttons: A, B, X, Y. When the player presses A their character Jumps. When the player presses BY their character Crouches. When the player presses X their character Punches. When the player presses Y their character Flies. When the player presses anything else Pause menu shows up Assume your program contains a variable named button that holds a character which indicates the button the player has pressed. Write the switch statement that displays a message explained the user the action that was taken.

User Andy
by
3.1k points

1 Answer

21 votes
21 votes

Answer:

Step-by-step explanation:

The following switch statement takes in the variable button as a parameter and outputs a statement saying what the character did due to the button being pushed.

switch (Character.toLowerCase(button.charAt(0))) {

case 'a': System.out.println("Your character has Jumped"); break;

case 'b': System.out.println("Your character has Crouched"); break;

case 'x': System.out.println("Your character has Punched"); break;

case 'y': System.out.println("Your character has Flown"); break;

default: System.out.println("Pause Menu has appeared"); break;

}

A video game controller contains the buttons: A, B, X, Y. When the player presses-example-1
User Simon Briche
by
3.1k points