Question: In the OnlineStudent class, implement the GPA method such that in addition to GPA calculation, it will print out the currentLocation and currentAffiliation. In the
In the OnlineStudent class, implement the GPA method such that in addition to GPA calculation, it will print out the currentLocation and currentAffiliation. In the Students main() method, initiate one OnlineStudent object and one Student object, and print out their GPAs.. I don't believe i created an online student in the student class.
Student.Java Code
import java.text.DecimalFormat;
public class Student { // data members for the class Student private String firstName; private String lastName; private String departmentIn; private int yearGraduation; private double [] grades; private UAClass classes[]; public Student(String firstName, String lastName, String departmentIn, int yearGraduation, UAClass[] classes, double[] grades) { // Overview: Constructor takes all of the student information // Requires: firstName, lastName, departmentIn, yearGraduation cannot be empty // Modifies: nil // Effects: initialization with student info; no class super(); this.firstName = firstName; this.lastName = lastName; this.departmentIn = departmentIn; this.yearGraduation = yearGraduation; this.classes = classes; this.grades = grades; } // getters and setters for all member variables public String getFirstName() { return firstName; }
public void setFirstName(String firstName) { this.firstName = firstName; }
public String getLastName() { return lastName; }
public void setLastName(String lastName) { this.lastName = lastName; }
public String getDepartmentIn() { return departmentIn; }
public void setDepartmentIn(String departmentIn) { this.departmentIn = departmentIn; }
public int getYearGraduation() { return yearGraduation; }
public void setYearGraduation(int yearGraduation) { this.yearGraduation = yearGraduation; } public UAClass[] getClasses() { // Overview: Append class information to list of classes for student // Requires: UAClass && Grades // Modifies: nil // Effects: Append a new element to classes; // append corresponding grade for class // update counter return classes; }
public void setClass(UAClass[] classes) { this.classes = classes; }
public double[] getGrades() { return grades; }
public void setGrades(double[] grades){ this.grades = grades; }
public static void main (String[] args){
UAClass classOne = new UAClass("Chen", "Shen", "Spring 2020", 3); UAClass classTwo = new UAClass("Jane", "Brown", "Fall 2019", 3); UAClass classes[] = new UAClass[]{classOne,classTwo};
double grades[] = {3.7, 3.1};
Student student = new Student("Missy","Lane", "MIS", 2020, classes, grades); student.calculateGPA();
}
public void calculateGPA() { double gpaSum = 0; double creditsAttempted =0; for(int i=0; i UAClass.Java Code public class UAClass { //data members private String teacherFirstName; private String teacherLastName; private String semesterOffered; private int numCredits; public UAClass(){ super(); } public UAClass (String teacherFirstName, String teacherLastName, String semesterOffered, int numCredits){ super(); this.teacherFirstName = teacherFirstName; this.teacherLastName = teacherLastName; this.semesterOffered = semesterOffered; this.numCredits = numCredits; } //Getters and setters for all member variables public String getTeacherFirstName() { return teacherFirstName; } public void setTeacherFirstName(String teacherFirstName) { this.teacherFirstName = teacherFirstName; } public String getTeacherLastName() { return teacherLastName; } public void setTeacherLastName(String teacherLastName) { this.teacherLastName = teacherLastName; } public String getSemesterOffered() { return semesterOffered; } public void setSemesterOffered(String semesterOffered) { this.semesterOffered = semesterOffered; } public int getNumCredits() { return numCredits; } public void setNumCredits(int numCredits) { this.numCredits = numCredits; } @Override public String toString() { return "UAClass [teacherFirstName=" + teacherFirstName + ", teacherLastName=" + teacherLastName + ", semesterOffered=" + semesterOffered + ", numCredits=" + numCredits + "]"; } } OnlineUAClass.Java Code public class OnlineUAClass extends UAClass { private String onlineTAFirstName; private String onlineTALastName; public OnlineUAClass(String teacherFirstName, String teacherLastName, String semesterOffered, int numCredits,String onlineTAFirstName,String onlineTALastName) { super(teacherFirstName,teacherLastName,semesterOffered,numCredits); this.onlineTAFirstName = onlineTAFirstName; this.onlineTALastName = onlineTALastName; } public String getOnlineTAFirstName() { return onlineTAFirstName; } public void setOnlineTAFirstName() { this.onlineTAFirstName = onlineTAFirstName; } public String getOnlineTALastName() { return onlineTALastName; } public void setOnlineTALastName() { this.onlineTALastName = onlineTALastName; } } OnlineStudent.Java Code public class OnlineStudent extends Student { private String currentLocation; private String currentAffiliation; public OnlineStudent(String firstName, String lastName, String departmentIn, int yearOfGraduation, UAClass[] classes, double [] grades, String currentLocation, String currentAffiliation) { super(firstName,lastName, departmentIn, yearOfGraduation, classes, grades); this.currentLocation = currentLocation; this.currentAffiliation = currentAffiliation; } public String getCurrentLocation() { return currentLocation; } public void setCurrentLocation(String currentLocation) { this.currentLocation = currentLocation; } public String getCurrentAffiliation() { return currentAffiliation; } public void setCurrentAffiliation(String currentAffiliation) { this.currentAffiliation = currentAffiliation; } public void GPA() { double total_grade=0; double [] grades = this.getGrades(); for(int i=0;i total_grade += grades[i]; } System.out.println("GPA is : " + total_grade/grades.length); System.out.println("Current location: " + currentLocation); System.out.println("Current Affiliation" + currentAffiliation); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
