Question
Follow the instructions below.This program provides a simplified example for selling tickets for three theaters within a movie house.In order to better reflect Object-Oriented principle,
Follow the instructions below.This program provides a simplified example for selling tickets for three theaters within a movie house.In order to better reflect Object-Oriented principle, much of the actual work takes place inside of the MovieHouse class.This example will be hard-coded with three theaters in order to reduce complexity.There is a sample of part of the output fileat the end of this problem.A full sample is also available on line.
abstract Ticket class (15)
There is a public static instance variable of type double for the basePrice.
The class has private instance integer variables for the values for the theaterNumber and seatNumber within the theater. The theater number may be 0, 1 or 2. The seat number ranges from 0 to one less than the total number of seats.
There is a private variable of type boolean that is set to true after a ticket is sold.
There is a variable of type boolean set to true after a reserved ticket is sold.
There is a constructor that accepts as input the theater number, seat number anda variable indicating if the seat is reserved.
There are publicget and set methodsfor the theaterNumber, seatNumber, reserved indicator and sold indicator.
There is a public equals method for the tickets. If the theaterNumber and seatNumber are the same the two objects are considered equal.
There is a public toString method that has the following String and which will be overridden in both ticket types below, but which is used via "super":
For Theater xxx seat number yyy which is
TotalCostForTicket interface (5)
This interface includes one variable taxRate which is .09.
It also includes an abstract method calculateTotalPrice which has no parameters and returns a value of type double.
GeneralTicket class (10)
This class is a subclass of Ticket and implements the TotalCostForTicket interface.
There is one additional private double variable totalPrice.
The constructor has the same parameters as Ticket which it uses to set these values. It also calls the calculateTotalPrice method.
The public calculateTotalPrice method from the interface is implemented by adding the tax to the basePrice and returns the totalPrice to the calling routine.
The public toString method is overridden.See the sample output.A line from this might read:
For Theater 1 Seat Number 16 which is GENERAL ADMISSION the price is $11.45
ReservedTicket class (10)
This class is a subclass of Ticket, and implements the TotalCostForTicket interface.
There is one additional private variable totalPrice.
The constructor has the same parameters as Ticket which it uses to set these values. It also calls the calculateTotalPrice method.
The public calculateTotalPrice method from the interface is implemented by adding the basePrice and the premium (See MovieHouse) together and adding the tax on that sum to calculate the totalPrice, and return the totalPrice to the calling routine.
The public toString method is overridden.See the sample output.A line from this might read:
For Theater 2 Seat Number 62 which is RESERVED the price is $15.26
MovieHouse class (25)
This is the most significant class as this most accurately models the object-oriented model. The MovieHouse is hard-coded with three theaters.
The instance variables include three ArrayList(s), theater0, theater1 and theater2. Each is instantiated with the Ticket class, allowing it to accept both ReservedTicket and GeneralTicket objects.
There is a private PrintWriter instance variable outputWriter.
There is a private String variable with the MovieHouse name called movieHouseName.
There is a public static double variable for the premium added to reserved tickets.It is set to 3.50 when it is declared.
There is also a private two-dimensional boolean array called theaterSeats with three rows. The constructor will have the variables needed to construct each row.
There is a single constructor with the name of the movie house, and three int variables indicating the number of seats in each of the three theaters.
The constructor directly sets the name of the movie theater.
The constructor creates the three rows of theaterSeats, with each row having a number of columns equal to the number of seats in that theater. (note: This may be a ragged array.)
The public void method setOutputWriter accepts a reference to a PrintWriter, and uses it to set the PrintWriter instance variable.
The public void method startSales accepts a theater number.
It creates a Random object using a seed that is 5*(the theater number) +10.
It then calculates the number of tickets to be sold as follows:
Generate a random number from 0 to one less than half the number of seats; Thenadd half the number of seats in the theater to this number. (Note: Use integer arithmetic when dividing by two.)
For each seat to be sold:
Randomly select a seat number from 0 to one less than the number of seats.
If the ticket is any third ticket starting with the 0TH(think modulo 3)
Call sellTicket with a newly created ReservedTicket based on the theater number and seat number, receiving an integer status in return
else
Call sellTicket with a newly created GeneralTicket based on the theater number and seat number, receiving an integer status in return
If the status is not zero you must retry ticket (i.e. decrement the counter).
The public method sellTicket accepts a Ticket reference and returns an int.
It retrieves the theater number and seat number of the ticket. (i.e. less than 0 or greater than 2)
If the theater number is not legitimate return 1
else if the seat number is illegitimate (i.e. greater than number of seats in theater -1 or less than 0)
return 2
else if the seat is taken - "that is the seat has been sold"
return 3
else
Mark the correct cell in theaterSeats as true
Add the ticket to the ArrayList of tickets for the correct theater
return 0
The public void method printSeatMaps has no parameters.
Prints out a header with the name of the movie house.
It prints out the seat map for each theater in groups of 10 to the output file.
The character S is printed if the ticket is sold, and V if it hasn't been.
See sample output.
The public void method printSalesRecords has no parameters.
For each theater it prints out all of the tickets in the ArrayList for that theater.
See sample output.
TestMovieHouse class (15)
This class which includes main does the following:
Scanner to read from the terminal.
Read in the name of the movie house.
Read in the number of seats in each of the three theaters.
MovieHouse based on the above data.
Read in the basePrice of a Ticket and set it equal to the static value basePrice.
Read in the name of an output file, and PrintWriter object for it.
Call setOutputWriter for the movie house with a reference to the PrintWriter.
For each theater call startSales for the movie house with an input parameter of the theater number starting with theater 0.
Call printSeatMaps for the movie house.
Call printSalesRecords for the movie house.
Close the output file.
Sample Input/Output From The Terminal
Please enter the name of the movie house: Magic Movie Emporium
Please enter the number of seats in theaters 0, 1 and 2 as integers.
Minimum 40 seats per theater: 83 40 97
Please enter the base price of a ticket: 10.50
Enter the name of the output file: movieoutput.txt
Sample Output File:
Welcome to Magic Movie Emporium
Theater 0 Seat Map
S S S S S S S S S S
S S S S S S S S S S
S S S S S S S S S S
S S S S S S S S S S
S S S S S S S S S S
S S S S V V V V V V
V V V V V V V V V V
V V V V V V V V V V
V V V
Theater 1 Seat Map
S S S S S S S S S S
S S S S S S S S S S
S V V V V V V V V V
V V V V V V V V V V
Theater 2 Seat Map
S S S S S S S S S S
S S S S S S S S S S
S S S S S S S S S S
S S S S S S S S S S
S S S S S S S S S S
S S S S S S S S S S
S S S S S S S S S S
S S S S S S S V V V
V V V V V V V V V V
V V V V V V V
The TicketRecord For Theater0
For Theater 0 Seat Number 46 which is RESERVED the price is $15.26
For Theater 0 Seat Number 8 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 14 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 12 which is RESERVED the price is $15.26
For Theater 0 Seat Number 35 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 40 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 44 which is RESERVED the price is $15.26
For Theater 0 Seat Number 39 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 7 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 6 which is RESERVED the price is $15.26
For Theater 0 Seat Number 38 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 28 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 30 which is RESERVED the price is $15.26
For Theater 0 Seat Number 43 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 29 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 51 which is RESERVED the price is $15.26
For Theater 0 Seat Number 32 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 19 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 15 which is RESERVED the price is $15.26
For Theater 0 Seat Number 2 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 25 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 1 which is RESERVED the price is $15.26
For Theater 0 Seat Number 49 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 4 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 37 which is RESERVED the price is $15.26
For Theater 0 Seat Number 36 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 0 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 33 which is RESERVED the price is $15.26
For Theater 0 Seat Number 50 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 22 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 47 which is RESERVED the price is $15.26
For Theater 0 Seat Number 11 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 52 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 5 which is RESERVED the price is $15.26
For Theater 0 Seat Number 18 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 34 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 41 which is RESERVED the price is $15.26
For Theater 0 Seat Number 27 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 3 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 20 which is RESERVED the price is $15.26
For Theater 0 Seat Number 9 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 17 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 31 which is RESERVED the price is $15.26
For Theater 0 Seat Number 10 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 45 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 13 which is RESERVED the price is $15.26
For Theater 0 Seat Number 53 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 24 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 16 which is RESERVED the price is $15.26
For Theater 0 Seat Number 48 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 23 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 21 which is RESERVED the price is $15.26
For Theater 0 Seat Number 26 which is GENERAL ADMISSION the price is $11.45
For Theater 0 Seat Number 42 which is GENERAL ADMISSION the price is $11.45
The TicketRecord For Theater1
For Theater 1 Seat Number 5 which is RESERVED the price is $15.26
For Theater 1 Seat Number 16 which is GENERAL ADMISSION the price is $11.45
For Theater 1 Seat Number 3 which is GENERAL ADMISSION the price is $11.45
For Theater 1 Seat Number 11 which is RESERVED the price is $15.26
For Theater 1 Seat Number 19 which is GENERAL ADMISSION the price is $11.45
For Theater 1 Seat Number 8 which is GENERAL ADMISSION the price is $11.45
For Theater 1 Seat Number 10 which is RESERVED the price is $15.26
For Theater 1 Seat Number 7 which is GENERAL ADMISSION the price is $11.45
For Theater 1 Seat Number 17 which is GENERAL ADMISSION the price is $11.45
For Theater 1 Seat Number 6 which is RESERVED the price is $15.26
For Theater 1 Seat Number 2 which is GENERAL ADMISSION the price is $11.45
For Theater 1 Seat Number 13 which is GENERAL ADMISSION the price is $11.45
For Theater 1 Seat Number 9 which is RESERVED the price is $15.26
For Theater 1 Seat Number 12 which is GENERAL ADMISSION the price is $11.45
For Theater 1 Seat Number 1 which is GENERAL ADMISSION the price is $11.45
For Theater 1 Seat Number 20 which is RESERVED the price is $15.26
For Theater 1 Seat Number 15 which is GENERAL ADMISSION the price is $11.45
For Theater 1 Seat Number 18 which is GENERAL ADMISSION the price is $11.45
For Theater 1 Seat Number 0 which is RESERVED the price is $15.26
For Theater 1 Seat Number 14 which is GENERAL ADMISSION the price is $11.45
For Theater 1 Seat Number 4 which is GENERAL ADMISSION the price is $11.45
The TicketRecord For Theater2
For Theater 2 Seat Number 62 which is RESERVED the price is $15.26
For Theater 2 Seat Number 72 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 71 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 11 which is RESERVED the price is $15.26
For Theater 2 Seat Number 29 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 48 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 1 which is RESERVED the price is $15.26
For Theater 2 Seat Number 18 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 20 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 28 which is RESERVED the price is $15.26
For Theater 2 Seat Number 19 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 73 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 36 which is RESERVED the price is $15.26
For Theater 2 Seat Number 47 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 50 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 57 which is RESERVED the price is $15.26
For Theater 2 Seat Number 40 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 32 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 7 which is RESERVED the price is $15.26
For Theater 2 Seat Number 74 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 44 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 66 which is RESERVED the price is $15.26
For Theater 2 Seat Number 75 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 25 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 2 which is RESERVED the price is $15.26
For Theater 2 Seat Number 70 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 4 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 51 which is RESERVED the price is $15.26
For Theater 2 Seat Number 63 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 58 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 61 which is RESERVED the price is $15.26
For Theater 2 Seat Number 54 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 16 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 38 which is RESERVED the price is $15.26
For Theater 2 Seat Number 60 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 37 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 3 which is RESERVED the price is $15.26
For Theater 2 Seat Number 56 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 52 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 24 which is RESERVED the price is $15.26
For Theater 2 Seat Number 76 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 34 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 0 which is RESERVED the price is $15.26
For Theater 2 Seat Number 49 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 43 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 69 which is RESERVED the price is $15.26
For Theater 2 Seat Number 8 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 10 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 22 which is RESERVED the price is $15.26
For Theater 2 Seat Number 64 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 15 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 55 which is RESERVED the price is $15.26
For Theater 2 Seat Number 39 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 12 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 9 which is RESERVED the price is $15.26
For Theater 2 Seat Number 6 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 27 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 41 which is RESERVED the price is $15.26
For Theater 2 Seat Number 23 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 21 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 65 which is RESERVED the price is $15.26
For Theater 2 Seat Number 68 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 33 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 53 which is RESERVED the price is $15.26
For Theater 2 Seat Number 45 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 67 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 35 which is RESERVED the price is $15.26
For Theater 2 Seat Number 59 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 26 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 14 which is RESERVED the price is $15.26
For Theater 2 Seat Number 30 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 13 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 31 which is RESERVED the price is $15.26
For Theater 2 Seat Number 46 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 5 which is GENERAL ADMISSION the price is $11.45
For Theater 2 Seat Number 42 which is RESERVED the price is $15.26
For Theater 2 Seat Number 17 which is GENERAL ADMISSION the price is $11.45
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres a Java implementation of the described movie ticket selling system import javaio import javautil abstract class Ticket public static double basePrice private int theaterNumber private int seatNu...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started