Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have to use my Student.java, Course.java, and Period.java to create the following method: *** I have written my Student.java, Course.java and Period.java below*** public

I have to use my Student.java, Course.java, and Period.java to create the following method:

*** I have written my Student.java, Course.java and Period.java below***

public static Course[] commonCourses(Student one, Student two)

given two students, return a list of all the courses both of the students are taking together in a new array (in any order).

the returned array should be just large enough to hold the results, and no larger; it should not contain any empty (null) entries.

if there are no courses in common, return null.

My Student.java is:

public class Student { String firstName; String lastName; int id; int gradYear; Course schedule[] = new Course[6]; public Student(String firstName, String lastName, int id, int gradYear) { this.firstName = firstName; this.lastName = lastName; this.id = id; this.gradYear = gradYear; }

public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public int getId() { return id; } public int getGradYear() { return gradYear; } public Course[] getSchedule() { return schedule; } public String toString() { return this.id+": "+this.lastName+", "+this.firstName+" - "+this.gradYear; } public boolean equals(Student other) { return id==other.id; } }

My Course.java:

public class Course { int department; int courseNum; String name; char day; int timeSlot; int credits; Student students[] = new Student[20];

private Period period;

public Course(int department, int courseNum, String name, char day, int timeSlot, int credits) { this.department = department; this.courseNum = courseNum; this.name = name; this.day = day; this.timeSlot = timeSlot; this.credits = credits; this.period = new Period(day, timeSlot); }

public int getDepartment() { return department; }

public int getCourseNumber() { return courseNum; }

public String getName() { return name; }

public Period getPeriod() { return period; }

public int getCredits() { return credits; }

public Student[] getRoster() { return students; }

public String toString(){ return this.department+":"+this.courseNum+" "+"[" + this.name + "]"+" "+ this.period + " " + "credits:"+this.credits; }

public boolean equals(Course other){ return courseNum==other.courseNum && department==other.department; } }

My Period.java:

public class Period { private char day; private int timeSlot;

public Period(char day, int timeSlot) { if(day >= 'a' && day <= 'z'){ day = (char) (day + (int)'A' - (int)'a'); } this.day = day; this.timeSlot = timeSlot; }

public char getDay() { return this.day; } public int getTimeSlot() { return this.timeSlot; } public String toString() { return ""+this.day + this.timeSlot; } public boolean equals(Period p) { return day == p.day && timeSlot == p.timeSlot; } public int compareTo(Period other){ if(equals(other)) { return 0; } else{ if(other.day == day) { if(timeSlot < other.timeSlot) { return -1; } else{ return 1; } } else{ String days = "SMTWHF"; int ind1 = days.indexOf(day); int ind2 = days.indexOf(other.day); if(ind1 < ind2){ return -1; } else{ return 1; } } } } }

Again my qustion is to USE Student.java, Period.java, Course.java that CREATES the method

public static Course[] commonCourses(Student one, Student two)

THE METHOD SHOULD DO THE FOLLOWING:

1. given two students, return a list of all the courses both of the students are taking together in a new array (in any order).

2. the returned array should be just large enough to hold the results, and no larger; it should not contain any empty (null) entries.

3. if there are no courses in common, return null.

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

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions