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
(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...
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 -...
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...
LE 7.2 Purpose: To learn how to create and use stand-alone class programs (classes withouta main method). When you take code out of the application class and put it in a class of its own, you make it reusable Prep Work: Chapter 7 Figure 7.6 shows you how an application class uses the services of a Java class in Figure 7.5. Although the code for LE 7.2 is different than the code in these figures, the concept is the same....
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...
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...
What if you had to write a program that would keep track of a list of rectangles? This might be for a house painter to use in calculating square footage of walls that need paint, or for an advertising agency to keep track of the space available on billboards. The first step would be to define a class where one object represents one rectangle's length and width. Once we have class Rectangle, then we can make as many objects of...
Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course { /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...
MUST BE WRITTEN IN C++ Objective: Learn how to define structures and classes, create and access a vector of structures, use sort with different compare functions. Assignment: Your program will use the same input file, but you will print the whole book information, not just the title. And, most importantly, this time you will take an object oriented approach to this problem. Detailed specifications: Define a class named Collection, in which you will define a structure that can hold book...
MUST BE WRITTEN IN C++ Objective: Learn how to define structures and classes, create and access a vector of structures, use sort with different compare functions. Assignment: Your program will use the same input file, but you will print the whole book information, not just the title. And, most importantly, this time you will take an object oriented approach to this problem. Detailed specifications: Define a class named Collection, in which you will define a structure that can hold book...