Question: How do I set up this type of menu, either with a switch or if else-if? Each option chosen should call a method. Thanks In

How do I set up this type of menu, either with a switch or if else-if? Each option chosen should call a method. Thanks

In Java:

How much should I study outside of class?

Study Hours per Week per Class Grade

15 A

12 B

9 C

6 D

0 F

Project Specifications:

  1. The menu driven program has the following options

A. Determine hours

B. Display Totals

C. End Program

  1. The user can select any menu option in any order they want.

    For example:

    • The user can start the program run option A, then option B , then option A, then option C, etc.
  2. Determine Hours to Study
    1. The user enters their full name and the number of credits they are taking.
    2. The user will then enter the grade they want, assume the same grade for all classes.
    3. The program determines the number of hours they have to study, assume they will study the same number of hours for each class.
    4. The program displays the users name in proper case, number of credits, expected total number of weekly study hours, and desired grade
    5. The information from 2.4 is also appended to a file named StudentsHoursGrades.txt.
  3. Display Total
    • The program displays the total number of students who used the program, the average credits taken, and the average study hours. In the following format
  4. Terminate - program is terminated

Edit - I have this code already:

import java.util.Scanner; import javax.swing.JOptionPane; import java.io.*;

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); }//end of main

public static String ProperCase (String input) { StringBuilder titleCase = new StringBuilder(input.length()); boolean nextTitleCase = true;

for (char c : input.toCharArray()) { if (Character.isSpaceChar(c)) { nextTitleCase = true; } else if (nextTitleCase) { c = Character.toTitleCase(c); nextTitleCase = false; }

titleCase.append(c); }

return titleCase.toString(); }

public static void Hours(String name, String input, int hourstostudy, int credits, char grade) throws IOException { name = JOptionPane.showInputDialog("What is your name?"); input = JOptionPane.showInputDialog("How many credits are you taking this semester?"); credits = Integer.parseInt(input); input = JOptionPane.showInputDialog("What grade would you like to earn?"); grade = input.charAt(0); if(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); FileWriter fwriter = new FileWriter("StudentsHoursGrades.txt"); PrintWriter outputFile = new PrintWriter(fwriter); outputFile.println(name); outputFile.println(credits); outputFile.println(hourstostudy); outputFile.println(grade); outputFile.close(); 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!