Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

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. NO ABSTRACT CLASS NEEDED.

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

GIVEN

/** 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()); } }

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

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions