Question: Continue from Question 1. Implement two more Java classes: OnlineStudent: a subclass of Student; add currentLocation and currentAffiliation as data members OnlineUAClass: a subclass of
Continue from Question 1. 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.
UAClass.java
public class UAClass {
private String teacherFirstName;
private String teacherLastName;
private int semesterOffered;
private int numCredits;
public UAClass() {
super();
}
public UAClass(String teacherFirstName, String teacherLastName, int semesterOffered, int numCredits) {
super();
this.teacherFirstName = teacherFirstName;
this.teacherLastName = teacherLastName;
this.semesterOffered = semesterOffered;
this.numCredits = numCredits;
}
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 int getSemesterOffered() {
return semesterOffered;
}
public void setSemesterOffered(int 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 + "]";
}
}
Student.java
public class Student {
private String firstName;
private String lastName;
private String departmentIn;
private int yearOfGraduation;
private UAClass classes[];
private int grades[];
public Student(String firstName, String lastName, String departmentIn, int yearOfGraduation, UAClass[] classes,
int[] grades) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.departmentIn = departmentIn;
this.yearOfGraduation = yearOfGraduation;
this.classes = classes;
this.grades = grades;
}
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 getYearOfGraduation() {
return yearOfGraduation;
}
public void setYearOfGraduation(int yearOfGraduation) {
this.yearOfGraduation = yearOfGraduation;
}
public UAClass[] getClasses() {
return classes;
}
public void setClasses(UAClass[] classes) {
this.classes = classes;
}
public int[] getGrades() {
return grades;
}
public void setGrades(int[] grades) {
this.grades = grades;
}
void getDetails(){
System.out.println("Student first Name : "+firstName);
System.out.println("Student last Name : "+lastName);
System.out.println("Student departement : "+departmentIn);
System.out.println("Student year of graduation : "+yearOfGraduation);
System.out.println("Student has following class");
for(int i=0;i System.out.println(classes[i]); } 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 : "+totalGrade/grades.length); } public static void main(String[] args) { UAClass classOne = new UAClass("Teacher FName1", "Teacher LName1", 1, 5); UAClass classTwo = new UAClass("Teacher FName2", "Teacher LName2", 2, 4); UAClass classThree = new UAClass("Teacher FName3", "Teacher LName3",3 ,3); UAClass classFour= new UAClass("Teacher FName4", "Teacher LName4", 4, 2); UAClass classes[] = new UAClass[]{classOne,classTwo,classThree,classFour}; int grades[] = {9,8,9,7}; Student student = new Student("Arnow","Angi", "CSE", 2019, classes, grades); student.getDetails(); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
