Question
(JAVA) An academic advisor wants a program that will compute a student GPA by reading a file that contains the name of the courses taken,
(JAVA) 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. The program will take, as run-time parameters, the folder directory where the grades file is stored and the first and last name of the student. For this testing your program, use the posted grades file called grade/Irving-Whitewood.cvs
To complete this assignment, we will use class Student.java completed from Chapter 10 from Intro to Java Programming, Comprehensive Version, 10th Edition. The purpose for this is to reuse functionality we have already created. Create a new java file, called MyStudent.java that inherits from the Student class. Inside this new file, do the following:
1. Static properties and behaviors
a. Create a private static ArrayList of courses private static ArrayList
You need to implement code that creates a Course object and adds that object to the courseList.
3. Non-static properties and behaviors
a. Create a public constructor that takes two Strings public MyStudent(String fname, String lname);
(implementation details explained below):
i. Determine the number of courses from the size of the courseList.
ii. Call super(fname, lname, numberOfCourses)
b. A public method to compute GPA use the String toString() method (implementation details explained below):
i. For each element in courseList
1. get courseName, creditHours, and letterGrade from the element
2. Call super.createCourse(courseName, creditHours, letterGrade) to create a course
ii. return super.toString() to get the output
Inside your ComputeStudentGPAProgram.java, write a main method that serves as the main launching code. This program will read the file (grade/Irving-Whitewood.cvs) that contains the grades for a student and the first and last name of the student. The program determines the GPA for the student.
Here, you will read the csv file (grade/Irving-Whitewood.cvs) to determine the students GPA. For each line in the file, you will need store this information by calling method addCourse() from class MyStudent. Once you have completed reading the file, close the file, and then proceed to do the following:
invoke the toString() method of this object inside a System.out.println statement
The output of your code will be:
Output: Student {firstname}, {lastname} has a {GPA value} GPA
Example: John Doe has a 3.4 GPA
NOTE
You will be provided with a file grade/Irving-Whitewood.cvs. Note that you cannot hardcode the first name and last name into your program directly. Your program MUST read the filename during the code execution.
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
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.
Where do I save the file so that java will be able to find it?
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started