1. Create, using NetBeans, a complete Java program called GameControl according
ID: 3664259 • Letter: 1
Question
1. Create, using NetBeans, a complete Java program called GameControl according to the following guidelines. This program must use a do loop and a switch statement to provide the following interac on with a user.
The program should prompt for an integer from 1 through 4, or q to quit.
If a user enters 0, your program should print "Up" and then prompt the user to enter another integer from 1 through 4, or q to quit.
If a user enters 1, your program should print "Down" and then prompt the user to enter another integer from 1 through 4, or q to quit.
If a user enters 2, your program should print "Le " and then prompt the user to enter another integer from 1 through 4, or q to quit.
If a user enters 3, your program should print "Right" and then prompt the user to enter another integer from 1 through 4, or q to quit.
If a user enters q, your program should print “Termina ng on receiving input q” and quit.
If the user enters any value other than 1, 2, 3, 4, or q, your program should print "Error; termina ng" and quit.
Explanation / Answer
public class GameControl {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("enter another integer from 1 through 4, or q to quit");
String InputValue= in.nextInt();
// Using switch-case
switch(InputValue) {
case 0: System.out.println("Up");
break;
case 1: System.out.println("Down");
break;
case 2: System.out.println("Le ");
break;
case 3: System.out.println("Right");
break;
case q: System.out.println("Termina ng on receiving input q");
break;
default: System.out.println("Error; termina ng");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.