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

USES OF JAVA PROGRAMMING, WHY WE USE JAVA IN PROGRAMMING INSTEAD OF OTHER P...

WHY WE USE JAVA IN PROGRAMMING INSTEAD OF OTHER PROGRAMMING LANGUAGE

Project, Prog. Concepts - Project The objective is to implement a menu - ba...

Prog. Concepts - Project The objective is to implement a menu - based system for Bank Accounts in order to simulate a very simple banking system. Many structures have to be declare

Need mahjong puzzle game, Need Mahjong puzzle game I want someone to mak...

Need Mahjong puzzle game I want someone to make this game ( Mahjong puzzle game) for me in Android ONLY. If you have high level programming knowledge in Android then please b

Explain about the interpreter in java, Machines should have Java interprete...

Machines should have Java interpreter for the Java byte code to get implemented. Linking is a very simple process and this feature helps while developing applications. Java compile

Prepare a computer graded test, Please check out the given instruction that...

Please check out the given instruction that I received to do the assessment. I can provide you that link to go on and submit the answers. To assess your coding skills, we would

Message "the quick brown fox jumps over the lazy dog"., public class Concat...

public class ConcatDemo { public static void main(String[] args) { String animal1 = "quick brown fox"; String animal2 = "lazy dog"; String article = "the";

Give the javascript code output, What is output of the following JavaScript...

What is output of the following JavaScript code? Str="Virtual University of Pakistan"; document.write(str.substring(5,str.length)) ;

Write a quality and complexity analysis report, Write a quality and complex...

Write a quality and complexity analysis report, JAVA Programming

What can you do with an exception once you''ve caught it, What can you do w...

What can you do with an exception once you've caught it? 1. Fix the difficulty and try again. 2. Do anything else instead. 3. Exit the application along with System.exit() 4

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