Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the following assignment for a Java application that is due by tomorrow. Here is Question 1: Implement two Java classes: Student: firstName, lastName,

I have the following assignment for a Java application that is due by tomorrow. Here is Question 1:

Implement two Java classes:

  • Student: firstName, lastName, departmentIn, yearGraduation, an array of UAClass this student is taking, an array of integers corresponding to the grades received for these classes
  • UA Class: teacherFirstName, teacherLastName, semesterOffered, numCredits

In the Student class, implement a method that calculates GPA. In the Students main() method, initiate one Student object and print out her GPA.

Implement two more Java classes:

  • OnlineStudent: a subclass of Student; add currentLocation and currentAffiliation as data members
  • OnlineUAClass: a subclass of UAClass; add onlineTAFirstName, onlineTALastName as data members

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 cannot get the GPA to work... I messed up the code somehow and can't figure out how to fix it. I would like to calculate GPA based on grades such as 98, 92, etc and from that come up with the GPA (3.89etc)... But I'm not sure how to do that. Please see my code below:

Student.Java code 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[]; // AF: // RI: 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 elemnt 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 void calculateGPA() { double totalGrade = 0; int totalClasses = 0; double GPA; for(int i=0;i totalGrade+=grades[i]; }; for(UAClass c : classes) totalClasses++; GPA = (totalGrade * totalClasses)/totalClasses; /*public double calculateGPA() { double sum = 0; int cls = 0; for(UAClass c : classes) cls++; for(double gds : grades) { sum = sum+gds; } // calculate GPA double gpa = sum/cls; return gpa; */ System.out.println("Student first Name : "+firstName); System.out.println("Student last Name : "+lastName); //System.out.println("Student grades for classes "); //double totalGrade=0; //for(int i=0;i //System.out.println("For class "+(i+1)+" Grade is : "+grades[i]); //totalGrade+=grades[i]; //} System.out.println("GPA is : " + GPA); //+totalGrade/grades.length); } public static void main (String[] args){

UAClass classOne = new UAClass("Zhpeng", "Chen", "Spring 2020", 3); UAClass classTwo = new UAClass("Sue", "Brown", "Fall 2019", 3); UAClass classes[] = new UAClass[]{classOne,classTwo};

double grades[] = {98, 92};

Student student = new Student("Grace","Ramon", "MIS", 2020, classes, grades); student.calculateGPA();

} }

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);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+ Are these impediments deliberate?

Answered: 1 week ago