Question: Program 2 (25 points) The files from this part should be put in package program2 Create a Java file ComputeStudentGPAProgram.java with a main method as
Program 2 (25 points)
The files from this part should be put in package program2
Create a Java file ComputeStudentGPAProgram.java with a main method as the main program for this part.
An academic advisor wants a program that will compute a student GPA by reading a file that contains the name of the courses taken, credit hours for each course, and grades earned from each course. For testing your program, use the grades file Irving-Whitewood.csv. Place this file in the top level of your project.
To complete this assignment, we will use class Student you revised in the previous program. Add import program1.Student at the beginning of your main program. You can then use class Student in the main program.
Your main program will begin by defining two string variables which contain the first and last name of a student. (These would be Irving and Whitewood for the example file provided) Then a string variable is initialized to the name of the file that contains the data for the student. This would be Irving-Whitewood.csv using the file provided above. Note: calculate this file name based on the first and last name of the student.
The program should create a Student object based on the first and last names already defined. Then course information is read from the file and used to add courses to the Student object. Finally, the toString method in Student is used to print out the students name and GPA.
NOTE
You will be provided with a file Irving-Whitewood.csv.
The structure of file Irving-Whitewood.cvs is:
CourseName1,creditHours,grade CourseName2,creditHours,grade CourseName3,creditHours,grade CourseName4,creditHours,grade CourseName5,creditHours,grade
Example:
Calculus,4,A Physics,4,A Computer Science,4,B English,3,C AmericanHistory,2,B
The GPA for this student is 3.294
Inside your ComputeStudentGPAProgram, you will need to use a mechanism to parse each line. While there are a variety ways to accomplish this, the String.split() method is the most feasible.
Evaluation
Your program will be evaluated with another student data file. The file will be put in the top level of your project. The name variables in your program will be changed to the new student and the program will be run with that change.
This is the code for Student.java:
public class Student { //Members private String _fname; private String _lname; private Course [] _cArry; private int _numCourses; //Constructor for student public Student(String fname, String lname, int numCourses){ this._fname = fname; this._lname = lname; this._numCourses = numCourses; _cArry = new Course[numCourses]; } //creates courses public void createCourse(String courseName, int creditHours, char letterGrade) { Course course = new Course(courseName, creditHours, letterGrade); for( int i =0; i< _cArry.length; i++) { if(_cArry[i] == null) { _cArry[i] = course; break; } } } //calculates gpa private static String computeGPA(Course[] _cArry) { String GPA = ""; for (int i = 0; i < _cArry.length; i++) { Course gpa = _cArry[i]; } return GPA; } //makes grades into numbers private int getPoints(char grade, int value){ switch (value = 0) { case 'A': value = 4; break; case 'B': value = 3; break; case 'C': value = 2; break; case 'D': value = 1; break; case 'F': value = 0; break; } return value; } public String toString() { return "Student " + _fname + " " + _lname + " has a " + computeGPA(_cArry) + " GPA"; } } This is the code for Course.java:
public class Course { private String name; private int hours; private char grade; Course(String name, int hours, char grade) { this.name = name; this.hours = hours; this.grade = grade; } public String getName() { return name; } public int getHours() { return hours; } public char getGrade() { return grade; } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
