/* The program demonstrate the usage of the switch statement It asks the user for a number then outputs a grade * */ import java.util.Scanner; // Needed for the scanner class public class ResGrade { public static void main(String[] args) { int grade; Scanner key = new Scanner(System.in); System.out.print("Please rate from 1 to 5\n"); System.out.print("1 is Very Good and 5 is Very Bad\n"); System.out.print("Enter the number: "); grade = key.nextInt(); /* Here we have 5 cases and a default, because grade is an integer And the inputs are between 1 and 5, we have to name the cases from 1 to 5 The default one is when the user enters other numbers that is not between 1 to 5 Note, after every statement we have to put a break, to break out the case. * */ switch(grade) { case 1: System.out.println("You gave the restaurant an A"); break; case 2: System.out.println("You gave the restaurant a B"); break; case 3: System.out.println("You gave the restaurant a C"); break; case 4: System.out.println("You gave the restaurant a D"); break; case 5: System.out.println("You gave the restaurant a F"); break; default: System.out.println("You enter a Invalid input"); break; } } }