Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Language is Java. Need subclasses of the superclass Course called MusicCourse an

ID: 3721162 • Letter: L

Question

Language is Java. Need subclasses of the superclass Course called MusicCourse and ComputerScienceCourse and then a class that uses both to provide the output shown.

Write a program that will prompt the user for information about a schedule of courses at a university and then print out the course schedule. Do not make any assumptions about the number of courses the user will enter. There are two types of courses in the schedule: Music (MUS) courses and Computer Science (COM) courses. You program will need to ask for different information from the user depending on the type of course. After the user has entered all the course information, your program should print out the schedule. You do not have to worry about courses that overlap in time, duplicate courses, or other scheduling problems that may arise.

Both Music and Computer Science courses have a subject, a course number, and a meeting time. In addition, Computer Science courses have a lab time associated with them. Music courses have a private lesson room and a private lesson instructor associated with them.

To hold course information, you program should define subclasses of the superclass Course called MusicCourse and ComputerScienceCourse. Course meeting times and lab times in the program are stored in objects of type MeetingTime. Times will be stored using the 24-hour clock, with the fraction 0.5 representing the one-half hour time. The source for both the Course and MeetingTime classes are attached.

In addition to other methods, both the MusicCourse and ComputerScienceCourse classes must have a method called toString() that returns a neatly formatted String representation of the object when called. You must use this method to print out the course onformation. MusicCourse.toString() and ComputerScienceCourse.toString()should call the toString() methods of the Course and MeetingTime classes to do their work. Do not duplicate the functionality of Course.toString() and MeetingTime.toString(). Do not make any changes or additions to either the Course class or the MeetingTime class; you must use them exactly as they are given.

Enter student name: Al Gorythmic

Enter a course subject: MUS

Enter course number: 100

Enter course start time and end time: 8.0 9.0

Enter private lesson room: OP 100

Enter private lesson instructor: Adams

Enter a course subject: COM

Enter course number: 101

Enter course start time and end time: 9.0 10.0

Enter lab start time and end time: 13.0 13.5

Enter a course subject: COM

Enter course number: 205

Enter course start time and end time: 14.0 15.5

Enter lab start time and end time: 15.5 16.0

Enter a course subject: MUS

Enter course number: 101

Enter course start time and end time: 10.0 12.0

Enter private lesson room: BAL 419

Enter studio instructor: Farkle

Enter a course subject: DONE

Course Schedule for Al Gorythmic

--------------------------------

MUS 100 from 8.0 to 9.0, private lesson in OP 100 with Adams

COM 101 from 9.0 to 10.0, lab from 13.0 to 13.5

COM 205 from 14.0 to 15.5, lab from 15.5 to 16.0

MUS 101 from 10.0 to 12.0, private lesson in BAL 419 with Farkle

/** A MeetingTime object represents a period of time during the day.
*/
public class MeetingTime
{
// The start of the meeting.
private double start;
// The end of the meeting.
private double end;
  
/** Create a new MeetingTime, initialized with a
* start and an end.
* @param theStartTime the start of the meeting time
* @param theEndTime the end of the meeting time
*/
public MeetingTime(double theStartTime, double theEndTime)
{
start = theStartTime;
end = theEndTime;
}
  
/** Get the start time of the time period.
* @return the start time.
*/
public double getStartTime()
{
return start;
}
  
/** Get the ending time of the time period.
* @return the ending time
*/
public double getEndTime()
{
return end;
}
  
/** Create a String representing this time.
* @return the String representing this time.
*/
public String toString()
{
return new String ("from " + start + " to " + end);
}
  
}

/** A generic course at a University
*/
public abstract class Course
{
  
// The course subject
private String subject;
// The course number
private int number;
// The time the course meets
private MeetingTime time;
  
/** Create a new Course object and initialize the course
* name, time and difficulty.
* @param theSubject the course subject
* @param theNumber the course number
* @param theTime the course time
*/
public Course (String theSubject, int theNumber, MeetingTime theTime)
{
subject = theSubject;
number = theNumber;
// Store a copy of the time object in the course object.
time = new MeetingTime (theTime.getStartTime(), theTime.getEndTime());
}
  
  
/** Get the time when the course meets.
* @return the time the course meets
*/
public MeetingTime getTime()
{
return new MeetingTime (time.getStartTime(), time.getEndTime());
}
  
/** Turn the course name, start time and end time
* into a string.
* @return a string representing the name and start and end times.
*/
public String toString()
{
return new String (subject + " "
+ number + " "
+ time.toString());
}
  
}

Explanation / Answer

MusicCourse.java

package com.chegg.question8;

public class MusicCourse extends Course {

private String lessonRoom;

private String lessonInstructor;

public MusicCourse(String theSubject, int theNumber, MeetingTime theTime, String lessonRoom,String lessonInstructor) {

super(theSubject, theNumber, theTime);

this.lessonRoom= lessonRoom;

this.lessonInstructor= lessonInstructor;

}

public String getLessonRoom() {

return lessonRoom;

}

public void setLessonRoom(String lessonRoom) {

this.lessonRoom = lessonRoom;

}

public String getLessonInstructor() {

return lessonInstructor;

}

public void setLessonInstructor(String lessonInstructor) {

this.lessonInstructor = lessonInstructor;

}

@Override

public String toString() {

return new String(super.toString()+", private lesson in " +lessonRoom + " with "+lessonInstructor);

}

}

ComputerScienceCourse.java

package com.chegg.question8;

public class ComputerScienceCourse extends Course {

private double labStartTime;

private double labEndTime;

public ComputerScienceCourse(String theSubject, int theNumber,

MeetingTime theTime, double labStartTime, double labEndTime) {

super(theSubject, theNumber, theTime);

this.labStartTime =labStartTime;

this.labEndTime =labEndTime;

}

public double getLabStartTime() {

return labStartTime;

}

public void setLabStartTime(double labStartTime) {

this.labStartTime = labStartTime;

}

public double getLabEndTime() {

return labEndTime;

}

public void setLabEndTime(double labEndTime) {

this.labEndTime = labEndTime;

}

/**

* Turn the course name, start time and end time into a string.

*

* @return a string representing the name and start and end times.

*/

public String toString() {

return new String(super.toString()+" , " +"lab from "+labStartTime+" to "+labEndTime);

}

}

CollegeScheduleTester.java

/**

*

*/

package com.chegg.question8;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

/**

* @author user

*

*/

public class CollegeScheduleTester {

/**

* @param args

*/

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

MeetingTime mt = null;MusicCourse mc= null;ComputerScienceCourse css=null;

List<MusicCourse> mcList= new ArrayList<MusicCourse>();

List<ComputerScienceCourse> cssList=new ArrayList<ComputerScienceCourse>();

System.out.println("Enter student name:");

String studentName = sc.next();

String courseSubject = null;

do{

System.out.println("Enter a course subject : ");

courseSubject = sc.next();

if(!(courseSubject.equals("COM"))||(courseSubject.equals("MUS"))) break;

System.out.println("Enter a course number : ");

int courseNumber = sc.nextInt();

System.out.println("Enter course start time and end time: ");

double startTime = 0.0 , endTime = 0.0;

double labStartTime = 0.0 , labEndTime = 0.0;

double[] vars1 = new double[2];

double[] vars2 = new double[2];

for(int i =0; i<vars1.length;i++) {

vars1[i] = sc.nextDouble();

}

startTime = vars1[0];endTime = vars1[1];

if(courseSubject.equals("MUS")){

System.out.println("Enter private lesson room : ");

String lessonRoom = sc.next();

System.out.println("Enter private lesson instructor : ");

String lessonInstructor = sc.next();

mt = new MeetingTime(startTime, endTime);

mc = new MusicCourse(courseSubject,courseNumber,mt,lessonRoom,lessonInstructor);

mcList.add(mc);

}else{

System.out.println("Enter lab start time and end time : ");

for(int i =0; i<vars2.length;i++) {

vars2[i] = sc.nextDouble();

}

labStartTime = vars2[0] ;labEndTime = vars2[1];

mt = new MeetingTime(startTime, endTime);

css = new ComputerScienceCourse(courseSubject,courseNumber,mt,labStartTime,labEndTime);

cssList.add(css);

}

} while (!courseSubject.equals("DONE"));

if(mcList.size()==0 || cssList.size()==0){

System.out.println(studentName +" has no courses scheduled");

}

else {

System.out.println("Course Schedule for "+studentName);

System.out.println("--------------------------------------------------------------------");

  

for(MusicCourse mcs : mcList){

System.out.println(mcs.toString());

}

for(ComputerScienceCourse cs : cssList){

System.out.println(cs.toString());

}

}

}

}