Question: Assignment: I need help writing this method for two classes. Method Summary abstract java.lang.String getSemesterCourseSchedule (Semester semester, int year) Get the person's course schedule for

Assignment:

I need help writing this method for two classes.

Method Summary
abstract java.lang.String getSemesterCourseSchedule(Semester semester, int year) Get the person's course schedule for a given semester/year combination.

Interface :

public interface HasCourseSchedule { /** * An example of a method header - replace this comment with your own * * @param y a sample parameter for a method * @return the result produced by sampleMethod */ public String getSemesterCourseSchedule(Semester semester, int year); }

Student Class that needs the interface method written:

public class Student extends UniversityMember implements HasCourseSchedule { private double gpa; private ArrayList transcript; private int creditsCompleted; public String getSemesterCourseSchedule(Semester semester, int year){ }

/** * Creates a student. * * @param firstName the first name of the student * @param lastName the last name of the student * @param id the student's id */ public Student(String firstName, String lastName, String id) { super(firstName, lastName, id); gpa = 0.0; transcript = new ArrayList(); creditsCompleted = 0; }

/** * @return the gpa */ public double getGpa() { return gpa; }

/** * Adds a course to the student's transcript. * * @param courseToAdd the course to add */ public void addCourse(Course c, Semester semester, int year, double grade) { CourseAttempted courseToAdd = new CourseAttempted(c, semester, year, grade); transcript.add(courseToAdd);

// the total number of credits attempted is the sum of // creditsCompleted and the number of credits of the course to be added // to the transcript int creditsAttempted = courseToAdd.course.getCredits() + creditsCompleted;

// gpa is computed by doing the following: // for each course attempted, multiply the number of credits by the // course grade. // gpa is the sum of the above for all the courses divided by the // number of total credits // double currentPoints = gpa * creditsCompleted + courseToAdd.grade * courseToAdd.course.getCredits();

gpa = currentPoints / creditsAttempted;

if (courseToAdd.grade > 0) creditsCompleted += courseToAdd.course.getCredits(); }

/** * Returns the list of courses as a String. * * @return the list of courses the student has taken */ public String getTranscript() { String courseList = "";

for (CourseAttempted ca: transcript) courseList = courseList + ca + " ";

return courseList; }

/** * Returns a String representation of a Student * * @return a string representing the student */ public String toString() { return super.toString() + "\tGPA = " + gpa + "\tCredits Completed = " + creditsCompleted + " Here are all the courses the student has taken so far" + " ---------------------------------------------------------------" + " " + getTranscript(); }

/** * Represents a course attempted by a student * in a given semester, year, and a grade * * @author Aparna Mahadev * @version 1 */ private class CourseAttempted { private Course course; private Semester semester; // Fall, Spring, Summer I, Summer II, Intersession private int year; private double grade;

/** * Constructor for objects of class CourseAttempted * @param c The course that was attempted by the student * @param semester Semester in which the course was taken * @param year Year in which the course was taken * @param grade Grade the student received for this course */ public CourseAttempted(Course c, Semester semester, int year, double grade) { this.course = c; this.semester = semester; this.year = year; this.grade = grade; }

public Semester getSemester() { return semester; } public int getYear() { return year; } /** * Returns a String representation of a course attempted */ public String toString() { String s = course.toString(); s += "\t" + semester + " " + year; s += "\t" + grade; return s; } } }

Faculty Class That Needs it Written as well :

public class Faculty extends Employee implements HasCourseSchedule { private String rank; private ArrayList coursesTaught; /** * Creates a faculty member. * * @param firstName first name of the faculty member * @param lastName last name of the faculty member * @param id id number of the faculty member * @param extension phone extension of the faculty member * @param salary salary of the faculty member */ public Faculty(String firstName, String lastName, String id, String extension, double salary, String rank) { super(firstName, lastName, id, extension, salary); this.rank = rank; coursesTaught = new ArrayList(); }

/** * Sets the faculty rank. * * @param rank the rank to set */ public void setRank(String rank) { this.rank = rank; } /** * Returns the rank. * * @return the rank */ public String getRank() { return rank; } /** * Adds a course to the faculty's list of courses taught. * * @param courseToAdd the course to add */ public void addCourse(Course c, Semester semester, int year, int enrollment) { CourseTaught courseToAdd = new CourseTaught(c, semester, year, enrollment); coursesTaught.add(courseToAdd); } /** * Returns the list of courses as a String. * * @return the list of courses the student has taken */ public String getCoursesTaught() { String courseList = "";

for (CourseTaught ct: coursesTaught) courseList = courseList + ct + " ";

return courseList; } /** * Prints a faculty member in a pretty format. * * @return a string representing the faculty member. */ public String toString() { return super.toString() + "\tFaculty Rank = " + rank + " Here are all the courses the faculty member has taught so far" + " ---------------------------------------------------------------" + " " + getCoursesTaught(); }

/** * Represents a course taught by a faculty member * in a given semester and year * * @author Karl R. Wurst * @author Aparna Mahadev * @version 1 */ private class CourseTaught { private Course course; private Semester semester; // Fall, Spring, Summer I, Summer II, Intersession private int year; private int enrollment;

/** * Constructor for objects of class CourseAttempted * @param c The course that was attempted by the student * @param semester Semester in which the course was taken * @param year Year in which the course was taken * @param enrollment Number of students enrolled */ public CourseTaught(Course c, Semester semester, int year, int enrollment) { this.course = c; this.semester = semester; this.year = year; this.enrollment = enrollment; }

public Semester getSemester() { return semester; } public int getYear() { return year; } public int getEnrollment() { return enrollment; } /** * Returns a String representation of a course attempted */ public String toString() { String s = course.toString(); s += "\t" + semester + " " + year; s += "\tEnrollment: " + enrollment; return s; } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!