Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

In this assignment, you will create 5 objects and get them to interact together. You will create theatres for which patrons will buy tickets from a box office to watch movies.

(1) The Movie, Ticket, Theatre and Patron Classes

You will need to define 4 objects as indicated below. You must choose appropriate attribute names so that the test program that follows compiles and runs properly.

  • Define a class called Movie that maintains the title of a movie as well as the amount of earnings it has made since it opened at the theatre.
  • Define a class called Theatre that keeps track of the Movie object that is currently playing in that theatre. A theatre should also have a seat capacity and keep track of how many seats have been sold for the movie playing.
  • Define a class called Ticket that represents a ticket to go and watch a movie. Each ticket is only valid for a specific Theatre object.
  • Define a class called Patron that keeps track of the name and the age of a person, the Ticket object that he/she has purchased and the NumberOfTickets he/she has purchased.

Write any necessary code so that the following test program works as indicated in the output that follows:

class TestProgram {

public static void main(String args[]) {

Movie m = new Movie("Megamind");

System.out.println(m.title);

System.out.println(m.earnings);

Theatre theatre = new Theatre(3);

System.out.println(theatre.capacity);

System.out.println(theatre.seatsSold);

theatre.moviePlaying = m;

Patron mary = new Patron("Mary",15);

System.out.println(mary.age);

System.out.println(mary.ticket);

mary.ticket = new Ticket(theatre);

System.out.println(mary.ticket.theatre.moviePlaying.title);

}

}

Megamind

The expected output is shown here on the right ... 0.0

Make sure that your code works before you continue. 3

0

15

null

Megamind

(2) The BoxOffice Class

Define a class called BoxOffice that keeps track of two theatres for which it sells movie tickets. The cost of a movie ticket is $4.75 for children under 11, $5. 50 for adults 66 years old or more and $13.50 for everyone else. The box office should also keep track of the movie that has made the most money and the patron, who has bought the most number of tickets in the past. Carefully examine the test program below. Understand how it is supposed to work. Then write the necessary methods so that the code runs properly, producing the correct results. You may NOT alter the test program ... the TA will be using it to test your code. Note that when tickets are sold to patrons, the title of the movie is provided. You will need to determine which theatre that movie is playing in. As a hint, you can compare two strings using the .equals() method in JAVA as follows:

String s1 = ...;

String s2 = ...;

if (s1.equals(s2))

...;

else

...;

Note as well in the program below that the bestMovie() will either be a previous movie that had the most earnings or one of the current playing movies ... whichever has the most earnings.

NOTE: Submit (on WebCT) all necessary .java and .class files needed to run. Note that if your internet connection at home is down or does not work, we will not accept this as a reason for handing in an assignment late ... so make sure to submit the assignment WELL BEFORE it is due !

Please NOTE that you WILL lose marks on this assignment if any of your files are missing. You will also lose marks if your code is not written neatly with proper indentation. See examples in the notes for proper style.

Here is the test program:

class BoxOfficeTestProgram {

public static void main(String args[]) {

// Create a box office with two theatres, each with a capacity of 5 seats

BoxOffice box = new BoxOffice(5, 5);

// Open up a couple of new movies at the box office

System.out.println("Theatre A opens movie: Ted");

box.openMovie("Ted", box.theatreA);

System.out.println("Theatre B opens movie: Spider-Man");

box.openMovie("The Amazing Spider-Man", box.theatreB);

// Now create some patrons

Patron p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13;

p1 = new Patron("Mary",15);

p2 = new Patron("Rose",26); p3 = new Patron("Kevin",7); p4 = new Patron("Ben",72);

p5 = new Patron("Kacy",65); p6 = new Patron("Yasi",11); p7 = new Patron("Taylor",19);

p8 = new Patron("Paul",17); p9 = new Patron("John",12);

p10 = new Patron("Kevin",14); p11 = new Patron("Anil",13); p12 = new Patron("Jit",16);

p13 = new Patron("Ross",66);

// Sell some tickets to the patrons

System.out.println("Patron 1 buys ticket to see Ted");

box.sellTicket(p1, "Ted");

System.out.println("Patrons 2,3 and 4 buy tickets to see Spider-Man");

box.sellTicket(p2, "Spider-Man");

box.sellTicket(p3, "Spider-Man");

box.sellTicket(p4, "Spider-Man");

System.out.println("Spider-Man seats remaining: " +

(box.theatreB.capacity - box.theatreB.seatsSold));

System.out.println("\nPatron 5 buys ticket to see The Giggling Giraffe");

box.sellTicket(p5, "The Giggling Giraffe");

System.out.println("\nPatrons 6 and 9 buy tickets to see Spider-Man");

box.sellTicket(p6, "Spider-Man");

box.sellTicket(p9, "Spider-Man");

System.out.println("Patrons 7, 8 and 10 buy tickets to see Ted");

box.sellTicket(p7, "Ted");

box.sellTicket(p8, "Ted");

box.sellTicket(p10, "Ted");

System.out.println("Patron 11 tries to buy tickets to see Spider-Man");

box.sellTicket(p11, "Spider-Man");

System.out.println("Spider-Man sold out ? " + box.theatreB.isFull());

System.out.println("\nPatrons 2, 6 and 10 return tickets");

box.returnTicket(p2);

box.returnTicket(p6);

box.returnTicket(p10);

System.out.println("\nPatron 10 tries to return a ticket again");

box.returnTicket(p10);

System.out.println("Spider-Man sold out ? " + box.theatreB.isFull());

System.out.println("Spider-Man seats remaining: " +

(box.theatreB.capacity - box.theatreB.seatsSold));

System.out.println("\nPatrons 11 and 12 buy tickets to see Spider-Man");

box.sellTicket(p11, "Spider-Man");

box.sellTicket(p12, "Spider-Man");

System.out.println("\nBest movie title: " + box.bestMovie().title);

System.out.println("Best movie earnings: " + box.bestMovie().earnings);

System.out.println("\nTheatre A opens movie: Ice Age");

box.openMovie("Ice Age", box.theatreA);

System.out.println("Patrons 1,2 buys ticket to see Ice Age ");

box.sellTicket(p1, "Ice Age");

box.sellTicket(p2, "Ice Age");

System.out.println("\nTheatre A opens movie: Magic Mike");

box.openMovie("Magic Mike", box.theatreA);

System.out.println("Patrons 1 buys ticket to see Magic Mike ");

box.sellTicket(p1, " Magic Mike");

System.out.println("\nBest movie title: " + box.bestMovie().title);

System.out.println("Best movie earnings: " + box.bestMovie().earnings);

System.out.println("Best patron is: " + box.bestPatron());

}

}

The expected output is:

Theatre A opens movie: Ted

Theatre B opens movie: Spider-Man

Patron 1 buys ticket to see Ted

Patrons 2,3 and 4 buy tickets to see Spider-Man

Movie is not currently playing

Movie is not currently playing

Movie is not currently playing

Spider-Man seats remaining: 5

Patron 5 buys ticket to see The Giggling Giraffe

Movie is not currently playing

Patrons 6 and 9 buy tickets to see Spider-Man

Movie is not currently playing

Movie is not currently playing

Patrons 7, 8 and 10 buy tickets to see Ted

Patron 11 tries to buy tickets to see Spider-Man

Movie is not currently playing

Spider-Man sold out ? false

Patrons 2, 6 and 10 return tickets

Patron does not have a ticket

Patron does not have a ticket

Patron 10 tries to return a ticket again

Patron does not have a ticket

Spider-Man sold out ? false

Spider-Man seats remaining: 5

Patrons 11 and 12 buy tickets to see Spider-Man

Movie is not currently playing

Movie is not currently playing

Best movie title: Ted

Best movie earnings: 40.5

Theatre A opens movie: Ice Age

Patrons 1,2 buy tickets to see Ice Age

Theatre A opens movie: Magic Mike

Patrons 1 buy tickets to see Magic Mike

Best movie title: Ted

Best movie earnings: 40.5

Best patron is: Mary

Java, Programming

  • Category:- Java
  • Reference No.:- M9522607

Have any Question?


Related Questions in Java

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As