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

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,

Execution process of java bytecode, Execution Process of Java bytecode ...

Execution Process of Java bytecode JVM are available for almost every operating system. Java bytecode is executed by employing any operating system's JVM. Hence achieve port

Ajax- html- xml- css and tomcat used in java, AJAX- HTML- XML- CSS and  To...

AJAX- HTML- XML- CSS and  Tomcat used in Java: Project Title: Zee Ads   Role                       : Developer Domain                  : Web Ads Environment

I need ios native app developer, I want someone to help me prepare a simple...

I want someone to help me prepare a simple inventory system. I am not a programmer trying to learn as i go. Skills required: Android, Java, iPhone, Mobile Phone, Objective

Simple Tasks, Use a FOR loop and give me the largest number divisible by 7 ...

Use a FOR loop and give me the largest number divisible by 7 11 13 17 use the number from 1 to 10000 (or even 100000)

Project, Hey, i have a project on java can you help me

Hey, i have a project on java can you help me

Need android geolocation service app, Need Android GeoLocation Service App ...

Need Android GeoLocation Service App Project Description: I want an android service app that will run on the background. The app has to get the users location (latitude an

Loops, Use a while loop to count down from 100 and display all the numbers ...

Use a while loop to count down from 100 and display all the numbers in the * following pattern (you have to figure out what the pattern is - don''t go below 0): * 100 99 97 94

Multitreading, what is multithreading in Java? Explain with example.

what is multithreading in Java? Explain with example.

Explain why java does not support multiple inheritance, Question: (a) ...

Question: (a) Differentiate between the following terms using suitable examples of your own:- (i) inheritance v/s composition (ii) subclass v/s superclass (iii) softwa

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