Program to create 5 objects and get them interact together, JAVA Programming

Assignment Help:

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


Related Discussions:- Program to create 5 objects and get them interact together

Intro to Programming, Overall Requirements Every phone number is broken up ...

Overall Requirements Every phone number is broken up into sections as shown below: Country Code Area Code Prefix Line Number 1 919 882 5000 Write a program to separate out a ph

Program to brute force search, Ask questionWrite a program BruteForceSearch...

Ask questionWrite a program BruteForceSearch that uses the brute-force approach given above and compare its running time on your computer with that of Binary Search for largeW.txt

Using the Case Study supplied, The report: Your report must describe the re...

The report: Your report must describe the requirements of the application, outline the design of the solution, and provide a testing procedure to prove the application works. In yo

I need viral script for facebook likes, Project Description: I need a Sc...

Project Description: I need a Script developer who can make script for me. Need urgently. Skills required: Java, Facebook Marketing, Javascript, PHP, Script Install

Malformedurlexception and unknownhostexception, When MalformedURLException ...

When MalformedURLException and UnknownHostException throws? Ans) When the particular URL is not connected then the URL throws MalformedURLException and If InetAddress? methods g

Program for users to play the game of brick, Task Your task is  to  w...

Task Your task is  to  write  a  Java  program  that  allows  users  to  play  the  game  of  Brickles. (note:  it  is  up  to  you  whether  to  use the  skeleton).  The prog

Why hub is used in networks, Why hub is used in networks? HUB: Hub is n...

Why hub is used in networks? HUB: Hub is networking component that can be used to connect the networks and it could also be used to extend the size of networks. In a simple way

We require responsible and serious programmer, We require responsible and s...

We require responsible and serious programmer Project Description: Big Data and On-line tools Website Liferay - JAVA - Portlets - JSP and JSF Skills required: J2EE,

Change to palindrome, A palindrome is a string that reads the same from bot...

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd