HELP WITH JAVA HOMEWORK!
ISM3230 Individual Assignment 5 – Classes Spring 2019
In this assignment you will generate a printout of a movie schedule for a movie theater. A schedule
consists of a series of days (7 in our case) and a list of movies for each day. Every day the first movie may
be shown at a different time. Each movie runs for its full length, followed by an intermission period to
allow for cleaning the theater. After the intermission period, which could be different for each day but
constant during the day, the next movie begins playing on the first available quarter hour (00, 15, 30, or
45 minutes past the hour). This scheduling continues until the end of the list of movies for the day. Refer
to the sample output for the general idea.
Requirements:
Use different classes to break down this complex problem into manageable pieces. The idea is to create
a set of classes that cooperate. What follows is a general overview, Instructions have more details.
A Movie object stores the movie name and how many minutes the movie lasts.
A Day object keeps the name of the day, the time when movies start to play for that day (as a Clock
object), and the length of the intermission between the movies. It also has an array of movies that play
that day, and some additional properties that help manage the movies array.
The Day object has also the ability to print out its schedule, that is, the day's movies with their show
times. The day schedule starts with the day name and is followed by one or more showings that include
the movie name, show time, and length. An intermission time, that is constant throughout the day, is
scheduled between showings. Then the start time for the following movie is moved to the next quarter
hour to have the movies start only at 00, 15, 30, and 45 minutes of the hour.
The solution should use the Clock class that was created in the Lab 10 to format the time for display,
and to advance the clock to generate the different show times for movies. Additional requirements are
listed in the instructions. Functionality already covered in Lab 9 is not included in these instructions.
The overall approach for integrating the Clock is to use the Clock object's abilities to advance time and
to return the String representation of the time it keeps. A Day object can have a Clock object as its
property - this clock should be used to do all the time-related work. With the Clock initialized to the first
show time of the day (this is done at Day instantiation), it should be advanced by the running time for
the movie, the intermission time, and adjusted to the next quarter, to find the times for the schedule.
The main driver program has only 2 responsibilities: to initialize the data and to run the printout. The
initialization part first creates and initializes 5 Movie objects. Then it creates and initializes 7 Day objects
and stores their references in an array called days. As a last step in the initialization, the movies are
assigned to the appropriate days by calling a method of the Day class that adds the movie to the day.
Finally, the driver loops through the seven days and instructs them to print their individual schedules,
thus generating the overall weekly schedule of days/movies.
Note: All of the user data is initialized in the driver program which is the "user" of the classes. New
schedules with different movies and different day start times and intermissions can be generated by
changing the initialization part of the driver - no changes to the class code in Clock, Day, and Movie are
allowed. This separates the program logic from the program data.
Code this assignment in a way that if the schedule contains different movies (with different names and
lengths), different start times for the days, and different intermission lengths, no changes would be
done to the code of Clock, Day, and Movie. All changes would be in the driver code only.
Instructions:
1) Create a new Project for the assignment. It will have a driver code, Clock class, Movie class, and Day
class.
2) Add a new class file for Clock. Copy the code from previous lab and edit it to contain the
following:
a) private properties for hours and minutes
b) constructor that takes int hours and int minutes to initialize a newly created clock
object to the indicated time
i) hours parameter should be checked for correct range (0-23). If out of range, hours should be
set to 0.
ii) minutes parameter should be checked for correct range (0-59). If out of range, minutes
should be set to 0.
c) there should be no default constructor
d) public String getCurrentTime() method that returns the string representation of
the time as documented in Lab 9
e) public void advanceTime(int minutes) that advances the clock forward the
number of indicated minutes, as documented in Lab 9
f) a new method public void advanceToNextQuarter() that moves the clock time to
the next closest quarter (0, 15, 30, 45 minutes). This method should use the advanceTime for
the actual advancement of the clock as the advanceTime already has the logic for the time
adjustments. Hint: Compute the number of minutes that are missing to get to the next quarter.
Use % operator. Then advance the clock by those minutes with advanceTime.
3) Add a Movie class with the following:
a) property private String name represents the movie's name
b) property private int length represents the movie's length in minutes
c) constructor Movie(String name, int length) initializes the name and length to
the passed values when creating a new Movie object.
d) there should be no default constructor
e) a getter method public int getLength() for movie length that will be used by the Day
class to compute the schedule
f) a method public String getTitle()returns the name of the movie followed by its
duration in minutes in the format "name (length min)" where name and length are the
movie properties
4) Add a Day class:
a) property private String name represents the name of the day. The names will be
"Mon", "Tue", "Wed", etc. as initialized by the constructor when instantiating the day objects in
the driver.
b) property private Clock startTime represents the starting time of the first movie of
the day. This is a Clock object and each day will have its own starting time object that can be
later manipulated with the Clock class methods.
c) property private int intermission holds the intermission time (cleaning time and
changing between movies) in minutes
d) property private Movie[] moviesToday is a declaration only of an array that will
hold the references to the Movie objects that should be played in this particular day. Movies will
be assigned to this array one by one with addMovie method (see below).
e) property private int totalMovies holds the total number of movies currently
assigned to the day. This needs to be initialized to zero by the constructor when the
moviesToday array is created. The property will be incremented by one whenever a movie is
added to the day's schedule (to the array moviesToday).
f) property private static final int maxMovies is a named constant that will be
hard-coded to 10 to indicate the maximum number of movies for a day. This constant will be
used to dimension the moviesToday array and also it will serve as an upper limit check
when adding movies to the day.
g) constructor Day(String name, int intermission, Clock startTime)
initializes the day's properties to the passed values when creating a new day object. In addition,
it will initialize totalMovies to 0 and create and dimension a new moviesToday array to
size maxMovies.
h) method public void addMovie(Movie m) takes a movie object as an argument and
adds it to the day's moviesToday array. totalMovies counter should be updated to
reflect the current number of movies in the array. The addition to the array should only happen
after a successful check is performed that ensures that the number of movies does not exceed
the maxMovies constant. Should a user try to add too many movies, an error message
"Cannot add more than maxMovies movies. Quitting." is printed and
program exits with System.exit(0).
i) method public void printDaySchedule() prints one line of output with the day's
name and the series of movies for that day. Each movie lists its start time, movie name, and
movie length. The string with the movie name and length is obtained from the Movie method
getTitle(). The printDaySchedule method should print only one line of text to the
screen and move the cursor to the next line. Hint: The easiest implementation is to start with an
empty string variable and build it up gradually from left to right with the += operator. The movie
details need be added in a loop. Movie methods need to be used to get the details of a
particular movie that is referenced in the moviesToday array. Movie class has the formatting
of a single movie. printDaySchedule method should do the formatting of the line (see
sample output).
5) Driver program: Most of the work is done in the Day class and the Clock class. All you have to do
here is to instantiate some movie objects and the seven day objects that represent our week. Then
the movies need to be assigned to the specific days with the addMovie() method. Finally, the
printDaySchedule() for each day is called to get the schedule printed. The movie details are:
Object reference name Movie name Movie length
vice "Vice" 132
fav "The Favourite" 119
boh "Bohemian Rhapsody" 134
life "Lifeboat" 34
week "Weekends" 15
Example of movie object instantiation:
Movie vice= new Movie("Vice",132);
Next is the instantiation of the day objects. We need 7 of them and they will all be called in
sequence to print their schedules, so the best approach is to create an array of day objects and
assign the 7 days to the array elements (as opposed to creating individual variable names as in the
case of the movies). The days have the following properties:
Name Intermission StartTime Clock
"Mon" 10 10:00
"Tue" 10 14:00
"Wed" 10 9:00
"Thu" 10 9:00
"Fri" 15 9:00
"Sat" 20 12:30
"Sun" 20 12:30
Create an array of day objects called days with 7 elements and assign the new day objects to it.
Example of a day object instantiation:
days[0]=new Day("Mon",10, new Clock(10,0));
Hint: Don't forget that we need to send a clock object to the day constructor, so make a new clock
object with the new keyword.
Now you need to assign the movies to the days. Use the addMovie() method on each day, and
pass the appropriate movie object reference (variable) to it. These are the movies that play on each
day:
Day Movies in order of play
Mon Lifeboat Weekends The Favourite Vice The Favourite
Tue Vice Bohemian Rhapsody The Favourite Vice
Wed Lifeboat Lifeboat Weekends Weekends
Thu The Favourite Vice Bohemian Rhapsody Weekends
Fri Weekends Vice Bohemian Rhapsody The Favourite Lifeboat
Sat Lifeboat Weekends The Favourite Bohemian Rhapsody Vice
Sun Weekends Weekends Vice Bohemian Rhapsody The Favourite
Example of assigning a movie to a day object:
//array days holds the day objects from Monday to Sunday
//assuming days[0] is Monday, life is Lifeboat
days[0].addMovie(life);
As a last step, call the method printDaySchedule() for each day to get the day schedule line
printed. For additional spacing, add an empty line to the output between the days.
Hint: It might be useful to first create a schedule without the quarter-hour adjustments to check
that the math in the Clock's advanceTime is working correctly with the movie lengths and
intermission times. The sample output without this adjustment is here:
Without quarter-hour adjustments:
Once you confirm that the timings are correct, you should include the quarter-hour adjustments to start
on the whole 15 minute points, as shown in the Sample output.
SAMPLE OUTPUT