Question: My question is the bolded part. In java, Determine Hours to Study The program will READ in data from a text file named StudyHours.txt .

My question is the bolded part. In java,

  1. Determine Hours to Study
    1. The program will READ in data from a text file named StudyHours.txt. The user corrects any bad data. The program updates the information in StudyHours.txt file. For example if the file contains a letter grade of K which is not a possible letter grade.

StudyHours.txt contains the following data:

  • first line full name
  • second line number of credits
  • third line grade desired for each class

Example format StudyHours.txt file

Aaron RODgers

12

A

Tom brady

9

K

philip Rivers

apple

c

Joe Theismann

15

B

  1. The program determines the total weekly study hours (for all classes)
  2. All data must be displayed in proper case such as Bob Smith, i.e. no names should be in all lower case or all upper case or a mix such as bob or sMiTh. Use a function to convert to proper case. Extra Credit 2.5 points
  3. The program displays the users name, number of credits, expected total number of weekly study hours, and desired grade
  4. The information from 2.4 is also appended to a file named StudentsHoursGrades.txt in the following format:
    • first line full name
    • second line number of credits
    • third line study hours
    • fourth line grade

My code I have so far is:

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

public class studyTime {

public static void main(String[] args) { 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. "); showMenu (); }//end of main public static void showMenu () { String input; char option; 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' || option== 'b') { Grades(); } else if (option == 'C' || option== 'c') { Display(); } else if (option == 'D' || option == 'd') { Goodbye(); } else JOptionPane.showMessageDialog(null, "Invalid menu option."); }

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(); }// end of proper case 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' || grade == 'b') hourstostudy = 12; else if(grade == 'C' || grade == 'c') hourstostudy = 9; else if(grade == 'D' || grade == 'd') hourstostudy = 6; else if(grade == 'F' || grade == 'f') hourstostudy = 0; else JOptionPane.showMessageDialog(null, "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); } showMenu(); 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); showMenu();

}// 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!