HELP WITH JAVA HOMEWORK!

profilemaigc
Lab10_2019S.pdf

ISM3230 Lab 10 Spring 2019

TOPIC: Attributes, methods, constructors

Background

This lab and Lab 9 will be used to build parts that can be used for Assignment 5. In the assignment you

will generate a weekly schedule for movie show times at a theater, such as:

This complex task is broken down into smaller parts. In Lab 9 you wrote a Clock class that could display

and manage time representation. In this lab you will build the code that takes care of the data for the

movies and the days.

See Sample Output to see the desired output from this Lab. The weekly schedule consists of 7 days, each

day has some properties (name, start time, intermission length) and contains some movies that are to

be played. The movies themselves have name and length in minutes.

Task/Requirements:

1) Create a new Netbeans project.

2) Build a class Movie that will be used to create movie objects. A movie has a name and a length (in

minutes). A movie object can also supply to its user a string with the name and length of the movie

that follows the format: "name (length min)"

Add a new class file to the package that is part of the project, call it Movie.

a) create a private property name that will hold the name of the movie

b) create a private property length that will hold the movie duration in minutes

c) create a default constructor for a movie object. The default constructor should set the name to

"No title" and the length to 0 minutes.

d) create a constructor for a movie object that will accept the movie name and the length and set

the properties to the passed parameters

e) create a public method getTitle that accepts no parameters and returns a string with the

name and length in the required format (see above).

3) In the driver, create some movie objects and call their method to print the name and length to the

screen as a test of the class' functionality. First create a movie object with the default constructor

(without parameters) and then create two movie objects with the following data:

Movie name Movie length

"Vice" 132

"The Favourite" 119

Lastly, use their getTitle method to print the formatted movie data to the screen.

In the driver, instantiate three movie objects and assign their references to variables of type Movie:

a) instantiate a movie object with its default constructor and save the reference

b) instantiate a movie object for "Vice" movie and save the reference

c) instantiate a movie object for "The Favourite" movie and save the reference

d) use the movie references to call the getTitle method for each object and print the return

value, one per line

e) print a separator to the screen to divide this part of the output from the remainder of the

program (use "---------")

4) Next, build a class Day that will hold the details about one day of the week. Each day has a name (for

example, "Mon"), the starting time when the first movie of the day is played ("09:00") and a day-

specific intermission length in minutes. This is the time of intermission between the movies on that

day.

Each day object will also keep track of the movies to be played on that day. Since there can be any

number of movies in a day, the movie objects are kept in an array. The total number of movies in

the day also has to be saved in an instance variable.

Add a new class file to the package that is part of the project, call it Day.

a) create a private property name that will hold the name of the day (e.g., Mon, Tue, Wed, etc.)

b) create a private property startTime that will hold the time of the first movie on that day as a

string

c) create a private property intermission that will hold the number of minutes between

movies

d) create a private property moviesToday that is a reference to an array of Movie objects that

play on that day. Note: this is a declaration only, no array is created/dimensioned nor initialized

e) create a private property totalMovies that will hold the number of movies which are saved

in the moviesToday array

f) create a named constant MAX_MOVIES = 10, this constant will be used to dimension the

moviesToday array and will be the maximum number of movies that are allowed to be played

on a particular day

g) create a constructor that will take parameters for name, startTime, and intermission.

The constructor should

i) set the properties to the passed parameters

ii) create and dimension the array moviesToday. Set the size to MAX_MOVIES constant.

Assign the array's reference to the moviesToday instance variable. Hint: Don't forget to

use new when creating an array.

iii) since the moviesToday array is empty, initialize the totalMovies variable to 0

h) create a method addMovie that will take a Movie object as a parameter and store its

reference in the array moviesToday

i) first check if adding another movie will not exceed the MAX_MOVIES limit. If it does exceed

the limit, print an error "Maximum movies per day exceeded" and stop the

program with System.exit(0). Use totalMovies for the check.

ii) use totalMovies as an index into the moviesToday array, it is pointing to an empty

array slot

iii) assign the passed Movie object to the array

iv) increment the totalMovies variable

i) create a public method showMovies that will print out the movies of the day. The method

should print out on the first line the name of the day and the starting time, separated by a

colon. Then on the second line it should print the details of the day's movies. Use a loop to get

all the movies in the moviesToday array, separate the movie details by a horizontal tab

character "\t". The individual movie data should be printed with the help of the movie's

getTitle method. The showMovies method should move the printing position to a new

line once it's finished printing.

5) Back in the driver again (continued from step 3):

f) instantiate a day object with the data: name: "Mon", starting time: "09:00", intermission length:

25

g) save the day object's reference to a variable

h) use the day object's addMovie method to add the "Vice" movie to the day as the first movie to

be played. Hint: use the stored reference to the movie object from step 3b.

i) use the day object's addMovie method to add "The Favourite" movie to the day as the second

movie to be played

j) use the day object's showMovies method to print the movie details for the day. Pay attention

to the new lines in the output.

SUBMITTING: You will need to submit multiple files for this Lab.

 Either submit each file separately, using the normal lab submission method.

 Or, Use File>Export Project>To Zip... from the main menu bar.

SAMPLE OUTPUT