import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; /* GPA_App.java ** Java application that, given an input file containing raw data (in the ** form of CSV-Strings) about students, the courses that they took, and the ** grades they earned in those courses, produces a report showing each ** student's GPA. (See the processStudent() method for a description of ** the assumed format of the lines/records in the input file and what ** each line of the report includes. ** ** CMPS 134 Fall 2025 Prog. Assg. #5 ** Author: R. McCloskey and < STUDENT's NAME > ** October 2025 ** Collaborated with: ... ** Known Defects: ... */ public class GPA_App { public static void main(String[] args) throws FileNotFoundException { // Establish the Scanner that will read from an input file Scanner input = getScanner(args); System.out.println(); printHeading(); while (input.hasNextLine()) { String line = input.nextLine(); // read next line/record from input file CSV_String csv = new CSV_String(line); // use it to create a CSV_String object processStudent(csv); } System.out.println("\nGoodbye!"); } /* Processes the given CSV_String object, culminating in a line of output ** being produced. The assumed format of the CSV_String is exemplified by ** ** Richard.Sharkface@rpi.edu,20020502,MUSIC432 3 C+,ART114 3 A,HIST257 3 A- ** ** That is: ** -- Field-0 is the student's e-mail address, assumed to be of the ** form .@, ** -- Field-1 is the student's birthdate (in yyyymmdd format), and ** -- each subsequent field includes three items of data, separated ** by spaces: course ID, # of credits, and letter grade earned by ** the student. ** ** The line of output that should be produced as a result of processing ** the CSV_String shown above is ** ** Sharkface, Richard 02-May-2002 3.33 ** ** In general, each such line of output includes the student's name ** (which can be inferred from the e-mail address), date of birth (in ** dd-Mon-yyyy format), and GPA (with two digits after the decimal point). */ private static void processStudent(CSV_String csv) { // Extract the email-address field from 'csv' and then // translate it into a name in , format: // < MISSING CODE > // Extract the calendar date field from 'csv' and then // translate it into the dd-Mon-yyyy format: // < MISSING CODE > // Use the remaining fields of 'csv' to compute the student's GPA: // < MISSING CODE > // Produce a line of output: // < MISSING CODE > } /* Given an e-mail address assumed to be in the form ** .@<...>, returns the person's ** name in , format. ** Example: "Mary.Smith@psu.edu" maps to "Smith, Mary". */ private static String emailAddrToName(String emailAddr) { return "Lincoln, Abraham"; // STUB } // Methods in support of converting a calendar date // in yyyymmdd format into dd-Mon-yyyy format. // ------------------------------------------------ /* Given a calendar date expressed in yyyymmdd format, returns the ** same date expressed in dd-Mon-yyyy format. ** Examples: ** "20191016" maps to "16-Oct-2019" ** "19870309" maps to "09-Mar-1987" */ private static String yyyymmdd_to_ddMONyyyy(String yyyymmdd) { return "1809-Feb-12"; // STUB! } /* Given a month number, returns the corresponding 3-character abbreviation. ** Each month's abbreviation is the first three letters of its name, with ** only the first letter capitalized. ** Examples: 3 maps to "Mar", 8 maps to "Aug" */ private static String monthAbbreviation(int monthNumber) { return "GLORP"; // STUB! } // End of methods in support of calendar date conversion. // Methods in support of computing GPA // ----------------------------------- /* Given a CSV-String each of whose fields identifies a course, its number ** of credits, and the letter grade earned in the course, computes the GPA. ** Example: "PHIL120 3 B,MATH114 4 A-,CHEM141 3 C+" maps to 3.07. */ private static double computeGPA(CSV_String csv) { return -1.0; // STUB } /* Returns the number of quality points associated to the given letter grade. ** Exhaustive mapping: ** "A" maps to 4.0 "C+" maps to 2.33 "F" maps to 0.0 ** "A-" maps to 3.67 "C" maps to 2.0 ** "B+" maps to 3.33 "C-" maps to 1.67 ** "B" maps to 3.0 "D+" maps to 1.33 ** "B-" maps to 2.67 "D" maps to 1.0 */ private static double gradeToQualityPoints(String grade) { if (grade.equals("A")) { return 4.0; } else if (grade.equals("A-")) { return 3.67; } else if (grade.equals("B+")) { return 3.33; } else if (grade.equals("B")) { return 3.0; } else if (grade.equals("B-")) { return 2.67; } else if (grade.equals("C+")) { return 2.33; } else if (grade.equals("C")) { return 2.0; } else if (grade.equals("C-")) { return 1.67; } else if (grade.equals("D+")) { return 1.33; } else if (grade.equals("D")) { return 1.0; } else if (grade.equals("F")) { return 0.0; } else { return 0.0; } // should never get here } // Methods in support of printing the heading and the output records. // ------------------------------------------------------------------ /* Given a student's name, birthdate, and GPA, prints a properly ** formatted output record. */ private static void printStudent(String name, String birthDate, double gpa) { System.out.printf("%-30s %11s %4.2f\n", name, birthDate, gpa); } /* Prints the column headings of the report. */ private static void printHeading() { System.out.printf(" %-22s %13s %3s\n", "Name", "Date of Birth", "GPA"); printChars('-', 50); System.out.println(); } /* Prints the specified character the specified number of times. */ private static void printChars(char ch, int numTimes) { for (int i=0; i != numTimes; i++) { System.out.print(ch); } } // Methods in support of establishing a Scanner // to be used for reading input data from a file. // ----------------------------------------------- /* Returns a Scanner object that can read from the file named by either ** args[0] or, if args[] has no elements, from a file named by the user ** in response to a prompt. */ private static Scanner getScanner(String[] args) { Scanner result = null; String fileName; if (args.length == 0) { fileName = getStringFromUser("Enter name of input file: "); } else { fileName = args[0]; } System.out.println("Program to read from file " + fileName); try { // Establish a Scanner to read from the file with the specified name. result = new Scanner(new File(fileName)); } catch (FileNotFoundException e) { System.out.println("No such file exists; program aborting."); System.exit(0); } return result; } /* Prints the given prompt and reads/returns a line of data read ** from standard input (the keyboard). */ private static String getStringFromUser(String prompt) { Scanner keyboard = new Scanner(System.in); System.out.print(prompt); return keyboard.nextLine(); } }