Question: In Java - How do I get a menu to repeat? For example in the following code. If my user picks A and then goes
In Java -
How do I get a menu to repeat?
For example in the following code. If my user picks A and then goes to the hours method, how do I get the user to get back to the menu to select another option when they are finished with that?
public class studyTime {
public static void main(String[] args) { // TODO Auto-generated method stub int hourstostudy=0,credits=0; String name, input; char grade, option; JOptionPane.showMessageDialog(null, "Welcome to the Study Time Calculator by Casie West. This program calculates the number of hours needed " + "to study to get the letter grade desired. The user can also see the averages and total of all users. "); input = JOptionPane.showInputDialog("A: How many hours do you need to study? B: What grade will you earn if you study this many hours? " + "C: Total number of students and average hours: D: Exit Program"); option = input.charAt(0); if(option=='A' || option == 'a') { Hours(); } else if (option =='B') { Grades(); } else if (option == 'C') { Display(); } else if (option == 'D') { Goodbye(); } }//end of main
public static void Hours() { int hourstostudy=0,credits=0; String name, input; char grade, option; name = JOptionPane.showInputDialog("What is your name? Please enter your first and last name such as Casie West."); input = JOptionPane.showInputDialog("How many credits are you taking this semester? Credits should be no more than 18 and divisible by three."); credits = Integer.parseInt(input); input = JOptionPane.showInputDialog("What grade would you like to earn?"); grade = input.charAt(0); if(grade == 'A' || grade == 'a') hourstostudy=15; else if(grade == 'B') hourstostudy = 12; else if(grade == 'C') hourstostudy = 9; else if(grade == 'D') hourstostudy = 6; else if(grade == 'F') hourstostudy = 0; else System.out.println("Invalid Grade"); hourstostudy *=(credits/3); name = ProperCase(name); try { FileWriter fwriter = new FileWriter("StudentsHoursGrades.txt", true); PrintWriter outputFile = new PrintWriter(fwriter); outputFile.println(name); outputFile.println(credits); outputFile.println(hourstostudy); outputFile.println(grade); outputFile.close(); } catch (Exception e) { System.out.println(e); } System.out.println("\tStudent Name: "+name); System.out.println("\tCredits: "+credits); System.out.println("\tTotal number of weekly study hours: "+hourstostudy); System.out.println("\tDersired Grade: "+grade);
}// end of Hours method
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
