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

Explain about the static classes, Explain about the Static classes A  ...

Explain about the Static classes A  class  can  have  static  variables    and    methods.    Static    methods    and    variables    are  associated  with  class  itself  an

Linked list, Write a program that takes as input a sequence of transactions...

Write a program that takes as input a sequence of transactions of the form "buy x; share(s) at $y each" or "sell x share(s) at $y each," assuming that the transactions occur on con

The tic-tac-toe program, Instructions Modify the program so that the co...

Instructions Modify the program so that the computer will generate moves for the ‘O' player (it must continue to accept user input for ‘X'). A simple way to do this is to use a

Functions, wap to find all the prime palindromic numbers

wap to find all the prime palindromic numbers

Write a algoritm to play blackjack , Draw: loops through the list of cards ...

Draw: loops through the list of cards drawing them in a single row starting from the screen position referred to by the 'x' and 'y' fields of the Hand class. You can limit the numb

Need Project Ideas.., I need some Unique Idea About my final Year Project ....

I need some Unique Idea About my final Year Project . It could be a Website or an Android application. I want to create Something very unique which in some sense benefits a society

Catch clause should be used to handle the exception, How does a try statem...

How does a try statement determine which catch clause should be used to handle the exception?

Describe about user security issues and social engineering, Describe about ...

Describe about User Security Issues and Social Engineering ? Contrary to popular belief most computer break-ins through external hackers don't happen since of great knowledge

Overview of struts?, Struts is a framework with set of co operating servlet...

Struts is a framework with set of co operating servlets, classes and JSP tags that create a reusable MVC 2 design.     1. Client (Browser) : A request from the cli

Build encyption decryption code, Hi, For my network and security class. I ...

Hi, For my network and security class. I have a project where I need to create a program that take an input and encrypts it and then you can also enter that value into another tex

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