Question

In: Computer Science

Let’s say that we work at some new video store and need to design some classes...

Let’s say that we work at some new video store and need to design some classes that will help us organize our database of movies. You are to write the following classes:

  1. Write a class called Video that will have the following properties:

  • Declare the instance fields title (String), length (int), avail (Boolean)

  • Declare two constructors

  • One default

  • One with title and length as parameters

  • Write a method that will output the fields of the objects by overriding the print method

  • Write an accessor method for availability:

 
 

public boolean getAvail()

  • Write a mutator method for availability!

 
 

public void setAvail(boolean b)

2. Write another class called Movie that will inherit the properties of the Video class but will also define two new fields: the movie rating and the name of the director. Give the movie class it’s own print method and constructors for default and with title, length, rating, and director as paramenters.

3. In the Main.java class create the following objects:

  • Video – Name: CPC Sports, 90 mins Available: No

  • Video - Name: CPC Through the Years, 2 hours, Available: Yes

  • Movie- Name: Mission Impossible 4, 2 hours 30 mins, Available: No, Director: Brad Bird, Rating: 4 stars

  • Movie- Name: Star Wars, 2 hours, Available: Yes: Director: George Lucas, Rating 5 stars

Can you change the availability of a movie using the mutator method from Video?

Given Code:

Main.java

class Main {
public static void main(String[] args) {
  
  
}
}

Video.java

class Video{
  
  
}

Movie.java

class Movie extends Video{
  
  
}

Solutions

Expert Solution

If anything is not clear please let me know in the comments.

Note: In order to change the availability of movie object we use super keyword. So what super does is that it is an object of base class i.e. Main class and thus we can access the set method of availability.

CODE:

class Video {
   String title;
   int length;
   private boolean avail;

   public Video() {
       this.avail = false; // means not available by default

   }

   public Video(String title, int length) {
       this.title = title;
       this.length = length;
   }

   public String toString() {
       String avail;
       if (getAvail() == true)
           avail = "Yes";
       else
           avail = "No";

       return "Video- Name: " + getTitle() + ", " + length + " mins, Available: " + avail;
   }

   // to accessors
   public String getTitle() {
       return title;
   }

   public int getLength() {
       return length;
   }

   public boolean isAvail() {
       return avail;
   }

   public boolean getAvail() {
       return avail;
   }

   void setAvail(boolean b) { // mutator
       this.avail = b;
   }

}

class Movie extends Video {
   int movieRating;
   String nameOfTheDirector;

   public Movie() {
       this.movieRating = 0; // by default
   }

   public Movie(String title, int length, boolean avail, String nameOfTheDirector, int movieRating) {

       super.title = title;
       super.length = length;
       super.setAvail(avail); // changing the availability of a movie using the mutator method from Video
       this.movieRating = movieRating;
       this.nameOfTheDirector = nameOfTheDirector;
   }

   @Override
   public String toString() {
       String avail;
       if (getAvail() == true)
           avail = "Yes";
       else
           avail = "No";

       return "Movie- Name " + getTitle() + ", " + getLength() + " hours" + ", Available: " + avail + ", Director: "
               + nameOfTheDirector + "Rating: " + movieRating + " stars";

   }

}

public class Main {
   public static void main(String[] args) {
       Video video1 = new Video("CPC SPorts", 90); // video object
       video1.setAvail(false); // not available

       Video video2 = new Video("CPC Through the Years", 2);
       video2.setAvail(true);

       Video movie1 = new Movie("Mission Impossible 4", 2, false, "Brad Bird", 4); // movie object
       Video movie2 = new Movie("Star Wars", 2, true, "George Lucas", 5);

       System.out.println(video1.toString());
       System.out.println(video2.toString());
       System.out.println(movie1.toString());
       System.out.println(movie2.toString());

   }

}

Output:

Code Screenshot:

Please If something is missing or not clear

Please Thumbs Up

Thank You


Related Solutions

MATLAB CODE Let’s say you need to write a small script that takes in the total...
MATLAB CODE Let’s say you need to write a small script that takes in the total amount of money entered, and a cost, and returns the correct change in quarters/dimes/nickels/pennies. Initialize counter variables for quarters, dimes, nickels and pennies to 0. Counter variables are used to keep track of how many of each coin are to be returned. Calculate the amount of change to be given using the ‘total’ and ‘cost’ variables. While there is still change to be given,...
MATLAB CODE Let’s say you need to write a small script that takes in the total...
MATLAB CODE Let’s say you need to write a small script that takes in the total amount of money entered, and a cost, and returns the correct change in quarters/dimes/nickels/pennies. Initialize counter variables for quarters, dimes, nickels and pennies to 0. Counter variables are used to keep track of how many of each coin are to be returned. Calculate the amount of change to be given using the ‘total’ and ‘cost’ variables. While there is still change to be given,...
4. Let’s say you work as a junior researcher in a consulting company that has been...
4. Let’s say you work as a junior researcher in a consulting company that has been hired by the American milk suppliers association to conduct a study on the milk market. Your assignment is to predict, using the demand and supply analyses, what will happen to the price and quantity (in gallons) traded (bought and sold) under the conditions stated below. What are your predictions? Explain fully using appropriate graphs (sketch). Consider each part separately.     (12 pts) Note: If...
For this assignment you will design a set of classes that work together to simulate a...
For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. You should design the following classes: - The ParkedCar Class: This class should simulate a parked car. The class's responsibilities are as follows: - To know the car's make, model, color, license number, and the number of minutes that the car has been parked. - The ParkingMeter Class: This class should simulate a parking meter. The class's only...
Let’s say that we have a 20-year mortgage with an original loan balance of $150,000 at...
Let’s say that we have a 20-year mortgage with an original loan balance of $150,000 at 7% interest per year. How much money (i.e., balance) do you still owe after the 7th year of the loan? (The loan is compounded monthly) . 1. $129,385 2. Cannot be determined 3. $118,902 4. $133,722
Let’s say we live in a country that gets very cold, in Northern America / Europe....
Let’s say we live in a country that gets very cold, in Northern America / Europe. In winter, we monitor the outside temperature, so that heaters can be switched on, inside the house. The idea is that, the colder it is outside, the warmer it should be inside. The heating side of things is just a heater that is either switched on, or switched off. Just from the information that has been given, please discuss this matter in depth. Provide...
In this question you will be asked to create some classes: Store, GroceryStore, and ClothingStore.
Use Python general directions: In this question you will be asked to create some classes: Store, GroceryStore, and ClothingStore. Store has the following attributes and methods: total_profit - this is a CLASS ATTRIBUTE that keeps track of the profit made in each instance of Store. (A class attribute is an attribute shared by all the instances of the class) __init__ - this is a constructor that is used to create an instance of a Store object. This constructor will do...
Using C++. For this assignment you will design a set of classes that work together to...
Using C++. For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. The classes you should design are : The ParkedCar class: This class should simulate a parked car. The class's responsibilities are: -to know the car's make, model,color ,license number,and the number of minutes that the car has been parked The ParkingMeter Class: This class should simulate a parking meter. the class's only responsibility is: -To know...
: Let’s say we are working with shapes having different types like 2d, 3D and so...
: Let’s say we are working with shapes having different types like 2d, 3D and so on. Using private access to fields of class design a class for rectangle.     c# for both 2d and 3d rectangle
Parking Ticket simulator For this assignment you will design a set of classes that work together...
Parking Ticket simulator For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. You should design the following classes: • The ParkedCar Class: This class should simulate a parked car. The class’s responsibili-ties are as follows: – To know the car’s make, model, color, license number, and the number of minutes that the car has been parked. • The ParkingMeter Class: This class should simulate a parking meter....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT