Please use the instructions at the beginning to write the program accordingly. T
ID: 3908192 • Letter: P
Question
Please use the instructions at the beginning to write the program accordingly. The program below the instructions is the student.java program mentioned in the intructions to use for the program. Please provide comments throughout. Thank you Program 1 (5 points): 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/lrving- Whitewood.cvs" To complete this assignment, we will use class Student.java completed from Chapter 10. 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-course> courseList b. A public static method to add to the ArrayList +public static void addCourse(String courseName, int creditHours, char letterGrade) You need to implement code that creates a Course object and adds that object to the courseList. a. Create a public constructor that takes two Stringspublic MyStudent(String fname, String Iname); 3. Non-static properties and behaviors (implementation details explained below) i. Determine the number of courses from the size of the courseList. i. Call super(fname, Iname, 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 i. return super.toString0 to get the output Inside your Compute StudentGPAProgram,java, write a main method that serves as the main launching code. This program will read the file ("grade/lrving-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 studentExplanation / Answer
i can't be very sure about it as there are missing files like course.java and the csv but i think this may come to help
/*
*MyStudent.java
*/
import java.util.ArrayList;
class MyStudent extends Student{
public MyStudent(String fName,String lName) {
numCourses=courseList.size();
super(fName, lName, numCourses))
}
public String calGPA()
{
int num;
double avgGPA;
for(Course course:courseList)
{
super.createCourse(course.courseName, course.creditHours, course.letterGrade);
}
for (int i = 0; i < this.numCourses; i++) {
if(cArry[i].letterGrade=='A')
avgGPA+=4.0;
else if(cArry[i].letterGrade=='B')
avgGPA+=3.0;
else if(cArry[i].letterGrade=='C')
avgGPA+=2.0;
else if(cArry[i].letterGrade=='D')
avgGPA+=1.0;
else if(cArry[i].letterGrade=='E')
avgGPA+=0.0;
num++;
}
return super.toString()+" has a "+avgGPA+" GPA";
}
private static ArrayList<Course> courseList;
public static void addCourse(String courseName,int creditHours,char letterGrade) {
Course createCourse = new Course();
createCourse.setCourseName(courseName);
createCourse.setCreditHours(creditHours);
createCourse.setLetterGrade(letterGrade);
courseList.add(createCourse);
}
}
/*
*StudentGPAProgram.java
*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class StudentGPAProgram{
public static void main(String[] args) throws IOException{
// open file input stream
BufferedReader reader = new BufferedReader(new FileReader("grade/Irwing-Whitewood.csv"));
// read file line by line
String line = null;
Scanner scanner = null;
int index = 0;
while ((line = reader.readLine()) != null) {
STring fname,lname,cname;char grade;int chours;
scanner = new Scanner(line);
scanner.useDelimiter(",");
while (scanner.hasNext()) {
String data = scanner.next();
if (index == 0)
fname=data;//assuming first column is first name
else if (index == 1)
lname=data;//assuming second column is last name
else if (index == 2)
cname=data;//assuming third column is course name
else if (index == 3)
chours=Integer.parseInt(data);//assuming column is course hours
else if(index==4)
grade=data.charAt(0);
else
System.out.println("invalid data::" + data);
MyStudent s=new MyStudent(fName, lName);
s.addCourse(cname, chours, grade);
System.out.println(s.calGPA());
index++;
}
}
//close reader
reader.close();
}
}