Question

(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. have been sold for the movie playing Define a class called Ticket that represents a ticket to go and watch a movie. only valid for a specific Theatre object. Define a class called Patron that keeps track of the age of a person as well as the Ticket object that he/she has purchased . A theatre should also have a seat capacity and keep track of how many seats . Each ticket is . Write any necessary code so that the following test program works as indicated in the output that follows public class TestProgram i public static void main (String args[]) I Movie m = new Movie (Despicable Me 3); 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 (15); System. out.println (mary.age) System.out.println (mary.ticket); mary.ticket- new Ticket (theatre); System. out.println (mary.ticket.theatre.moviePlaying. title); Despicable Me 3 0.0 The expected output is shown here on the right → Make sure that your code works before you continue. 15 null Despicable Me 3

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

class Movie //movie class

{

String title; //title of the movie

double earnings; //earning for the movie

public Movie(String movieTitle) { //constructor to initialize title of the movie

title=movieTitle;

}

}

class Theatre //theatre class

{

int capacity; //capacity of the theater

int seatsSold; //seats sold

Movie moviePlaying; //movie being played

public Theatre(int cap) { //constructor to initialize capacity

capacity=cap;

}

}

class Ticket //ticket class

{

Theatre theatre; //theater of which the ticket is

public Ticket(Theatre t) { //constructor to initialize the theater

theatre=t;

}

}

class Patron //Patron class

{

int age; //age of patron

Ticket ticket; //patron's ticket

public Patron(int a) { //constructor to initialize age of patron

age=a;

}

}

public class TestProgram {

public static void main(String[] args) { //main function

Movie m= new Movie("Despicable Me 3");

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(15);

System.out.println(mary.age);

System.out.println(mary.ticket);

mary.ticket= new Ticket(theatre);

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

}

}

SCREENSHOTS:

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
(1) The Movie, Ticket, Theatre and Patron Classes You will need to define 4 objects as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (1) The Movie, Ticket, Theatre and Patron Classes You will need to define 4 objects as...

    (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...

  • I have this java program that I need to add an abstract method and polymorphism to...

    I have this java program that I need to add an abstract method and polymorphism to it : import java.util.Scanner; //class and encapsulation class BookTheTicket { private String movieName; private String theatreName; private int ticketCost; void myAllmovies() { System.out.println("-------Listing the movies:------"); System.out.println(" 1.DDLJ ------------ $40 \n 2.kkr---------$.50 \n 3.game-movie --------$60 \n 4.fun movie ----- $.70 "); } } // inheritence class theater extends BookTheTicket{ private int numOfTickets; void theater() { System.out.println("*******Listing the theatre:******* \n 1.coco cola tld \n 2.koi gandhi...

  • You will be writing a Library simulator involving multiple classes. You will write the LibraryItem, Patron,...

    You will be writing a Library simulator involving multiple classes. You will write the LibraryItem, Patron, and Library classes and the three classes that inherit from LibraryItem (Book, Album and Movie). All data members of each class should be marked as private and the classes should have any get or set methods that will be needed to access them. **USE PYTHON 3 ONLY!!! Here are descriptions of the three classes: LibraryItem: id_code - a unique identifier for a LibraryItem -...

  • ​I have to create two classes one class that accepts an object, stores the object in...

    ​I have to create two classes one class that accepts an object, stores the object in an array. I have another that has a constructor that creates an object. Here is my first class named "ShoppingList": import java.util.*; public class ShoppingList {    private ShoppingItem [] list;    private int amtItems = 0;       public ShoppingList()    {       list=new ShoppingItem[8];    }       public void add(ShoppingItem item)    {       if(amtItems<8)       {          list[amtItems] = ShoppingItem(item);...

  • I need help with a java error Question: Consider a graphics system that has classes for...

    I need help with a java error Question: Consider a graphics system that has classes for various figures—say, rectangles, boxes, triangles, circles, and so on. For example, a rectangle might have data members’ height, width, and center point, while a box and circle might have only a center point and an edge length or radius, respectively. In a well-designed system, these would be derived from a common class, Figure. You are to implement such a system. The class Figure is...

  • 1) Introduction to Objects (with Constructors and Properties) We need to answer the question which are...

    1) Introduction to Objects (with Constructors and Properties) We need to answer the question which are below. and instruction are given down starting with part(b). Just we need to copy paste code file and follow the instruction and answer related to them. a) Enter the following program.Answer The questions below the codes, Notice that it consists of two classes that will go into the same project. Please put each class into its own code file (use Lab5_1 for the Project...

  • 1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System....

    1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System.out.println("test"); } } 1. The code compiles but will not print anything since t does not invoke the run method. 2. The code will not compile since you cannot invoke "this" in a static method. 3. The program compiles, runs, and prints tests on the console. 2. What will the following example...

  • Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person...

    Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person and Student represent individuals with a first and last name as String class variables, and Student has an additional int class variable that represents a ID number. The Roster class represents a group of people that are objects of either the Person or Student class. It contains an ArrayList. The Person class has been completed for you with class variables, a constructor, and a...

  • Task #3 Arrays of Objects 1. Copy the files Song java (see Code Listing 7.1), Compact...

    Task #3 Arrays of Objects 1. Copy the files Song java (see Code Listing 7.1), Compact Disc.java (see Code Listing 7.2) and Classics.txt (see Code Listing 7.3) from the Student Files or as directed by your instructor. Song.java is complete and will not be edited. Classics.txt is the data file that will be used by Compact Disc.java, the file you will be editing. 2. In Compact Disc.java, there are comments indicating where the missing code is to be placed. Declare...

  • This java assignment will give you practice with classes, methods, and arrays. Part 1: Player Class...

    This java assignment will give you practice with classes, methods, and arrays. Part 1: Player Class Write a class named Player that stores a player’s name and the player’s high score. A player is described by:  player’s name  player’s high score In your class, include:  instance data variables  two constructors  getters and setters  include appropriate value checks when applicable  a toString method Part 2: PlayersList Class Write a class that manages a list...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT