Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(1) The Movie, Ticket, Theatre and Patron Classes You will need to define 4 obje

ID: 3879657 • Letter: #

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. A theatre should also have a seat capacity and keep track of how many seats have been sold for the movie playing. . Each ticket is 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 Write any necessary code so that the following test program works as indicated in the output that follows: public class TestProgram public static void main (String argst1) Movie m = new Movie ("Despicablo Me 3"); System.out.printin(m.title); System.out.printin (m.earnings) Theatre theatre new Theatre (3); System.out.printin (theatre.capacity) System.out.printin (theatre.seatsSold) theatre .moviePlaying m; Patron mary = new Patron (15); System.out.printin (mary.age) System.out.printin (mary.ticket) mary.ticket- new Ticket (theatre) System.out.printin (mary ticket.theatre.moviePlaying. title) Despicable Ne 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

Explanation / Answer

Hello, I have a solution for you. Implemented everything as per the requirements. Defined following things in this answer.

//Movie.java

public class Movie {

      String title;

      double earnings;

      /**

      * Constructor to initialize a Moveie object

      */

      public Movie(String title) {

            this.title = title;

            earnings=0;

      }

      /**

      * Useful getters and setters

      */

      public String getTitle() {

            return title;

      }

      public void setTitle(String title) {

            this.title = title;

      }

      public double getEarnings() {

            return earnings;

      }

      public void setEarnings(double earnings) {

            this.earnings = earnings;

      }

     

     

}

//Theatre.java

public class Theatre {

      Movie moviePlaying;

      int capacity;

      int seatsSold;

      /**

      * Constructor to initialize a Theatre object

      * @param capacity- max seat capacity

      */

      public Theatre(int capacity) {

            this.capacity = capacity;

            seatsSold=0;

      }

      /**

      * Useful getters and setters

      */

      public Movie getMoviePlaying() {

            return moviePlaying;

      }

      public void setMoviePlaying(Movie moviePlaying) {

            this.moviePlaying = moviePlaying;

      }

      public int getCapacity() {

            return capacity;

      }

      public void setCapacity(int capacity) {

            this.capacity = capacity;

      }

      public int getSeatsSold() {

            return seatsSold;

      }

      public void setSeatsSold(int seatsSold) {

            this.seatsSold = seatsSold;

      }

     

     

}

//Ticket.java

public class Ticket {

      Theatre theatre;

      /**

      * Initializing a Ticket

      * @param theatre - the theatre where the ticket is valid

      */

      public Ticket(Theatre theatre) {

            this.theatre = theatre;

      }

      /**

      * Useful getter and setter

      */

      public Theatre getTheatre() {

            return theatre;

      }

      public void setTheatre(Theatre theatre) {

            this.theatre = theatre;

      }

     

}

//Patron.java

public class Patron {

      int age;

      Ticket ticket;

      /**

      * Initializing a Patron

      * @param age- age of the Patron

      */

      public Patron(int age) {

            this.age = age;

      }

      /**

      * Useful getters and setters

      */

      public int getAge() {

            return age;

      }

      public void setAge(int age) {

            this.age = age;

      }

      public Ticket getTicket() {

            return ticket;

      }

      public void setTicket(Ticket ticket) {

            this.ticket = ticket;

      }

     

}

//TestProgram.java

public class TestProgram {

      /**

      * Using the driver program given in the question

      */

      public static void main(String[] args) {

           

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

      }

}

/*OUTPUT*/

Despicable me 3

0.0

3

0

15

null

Despicable me 3