Question

JAVA Learning Objectives: To be able to code a class structure with appropriate attributes and methods....

JAVA Learning Objectives: To be able to code a class structure with appropriate attributes and methods. To demonstrate the concept of inheritance. To be able to create different objects and use both default and overloaded constructors. Practice using encapsulation (setters and getters) and the toString method.

Create a set of classes for various types of video content (TvShows, Movies, MiniSeries). Write a super or parent class that contains common attributes and subclasses with unique attributes for each class. Make sure to include the appropriate setter, getter methods and toString to display descriptions in a nicely formatted output. In addition to default constructors, define overloaded constructors to accept and initialize class data. When using a default constructor, use the setter from the main program to set values. Use a static variable to keep track of the number of objects in the video library. Display the number of items prior to listing them.

Data for movies should contain attributes for the title, release date, genre, studio, and streaming source (Netflix, Prime or Hulu).

Data for TvShow should contain the title, genre (same as others), date of the first episode, number of seasons, network, and running time.

Data for MiniSeries should include attributes for title, genre (same as others), number of episodes, running time, lead actor or actress

.Create a main driver class to create several objects of each type of video content. Use examples of both the default and overloaded constructors. Then display your complete video library with all fields.

Homework Answers

Answer #1

Inheritance.java

//parent class for all the sub classes
class VideoContent{

//data variable
private String title;
private String genre;

//Static variable that keeps track of number of objects in the Video Library
public static int numberOfObjects = 0;

//default constructor
public VideoContent(){
this.title="";
this.genre="";
numberOfObjects++;
}

//overloaded constructor
public VideoContent(String title, String genre){
this.title = title;
this.genre = genre;
numberOfObjects++;
}

//setter for title
public void setTitle(String title){
this.title = title;
}
//getter for title
public String getTitle(){
return this.title;
}

//setter for genre
public void setGenre(String genre){
this.genre = genre;
}

//getter for genre
public String getGenre(){
return this.genre;
}

//toString method
public String toString(){
return "VideoContent\n____________\nTitle: "+getTitle()+"\nGenre: "+getGenre()+"\n";
}
}


//Movieclass that inherits from VideoContent
class Movies extends VideoContent{

//data variables
private String releaseDate;
private String studio;
private String streamingSource;

//default constructor
public Movies(){
this.releaseDate ="";
this.studio = "";
this. streamingSource = "";
}

//overloaded constructor
public Movies(String title, String date, String genre, String studio, String source){
super(title,genre);
this.releaseDate = date;
this.studio = studio;
this.streamingSource = source;
}

//setters
public void setReleaseDate(String date){
this.releaseDate = date;
}

public void setStudio(String studio){
this.studio = studio;
}

public void setStreamingSource(String source){
this.streamingSource = source;
}

//getters
public String getReleaseDate(){
return this.releaseDate;
}

public String getStudio(){
return this.studio;
}

public String getStreamingSource(){
return this.streamingSource;
}

//toString method
public String toString(){
return "Movie\nTitle: "+getTitle()+"\nRelease Date: "+
getReleaseDate()+"\nGenre: "+getGenre()+"\nStudio: "+
getStudio()+"\nStreaming Source: "+getStreamingSource()+"\n";
}

}

//TvShow class that inherits from VideoContent class
class TvShow extends VideoContent{

//data variables
private String dateOfE1;
private int seasons;
private String network;
private String runningTime;

//default constructor
public TvShow(){
this.dateOfE1 = "";
this.seasons = 0;
this.network = "";
this.runningTime = "";
}

//overloaded constructor
public TvShow(String title, String genre, String date, int seasons,
String network, String runningTime){
super(title,genre);
this.dateOfE1 = date;
this.seasons = seasons;
this.network = network;
this.runningTime = runningTime;
}

//setters
public void setDateOfE1(String date){
this.dateOfE1 = date;
}

public void setSeasons(int num){
this.seasons = num;
}

public void setNetwork(String network){
this.network = network;
}

public void setRunningTime(String time){
this.runningTime = time;
}

//getters
public String getDateOfE1(){
return this.dateOfE1;
}

public String getNetwork(){
return this.network;
}

public int getSeasons(){
return this.seasons;
}

public String getRunningTime(){
return this.runningTime;
}

//to string method
public String toString(){
return "TV Show\nTitle: "+getTitle()+"\nGenre: "+getGenre()+
"\nDate of First Episode: "+getDateOfE1()+"\nNumber of Seasons: "+
+getSeasons()+"\n Network: "+getNetwork()+
"\nRunning Time: "+getRunningTime()+"\n";
}
}

//calss MininSeries which inherits from VideoContent class
class MiniSeries extends VideoContent{

//data variables
private int episodes;
private String runningTime;
private String lead;

//default constructor
public MiniSeries(){
this.episodes =0;
this. runningTime ="";
this.lead ="";
}

//overloaded constructor
public MiniSeries(String title, String genre, int episodes, String runningTime
, String lead){
super(title, genre);
this.episodes =episodes;
this.runningTime = runningTime;
this.lead = lead;
}

//setters
public void setEpisodes(int episodes){
this.episodes = episodes;
}

public void setRunningTime(String runningTime){
this.runningTime = runningTime;
}

public void setLead(String lead){
this.lead = lead;
}

//getters
public int getEpisodes(){
return this.episodes;
}

public String getRunningTime(){
return this.runningTime;
}

public String getLead(){
return this.lead;
}

//toString method
public String toString(){
return "Mini Series\nTitle: "+getTitle()+"\nGenre: "+
getGenre()+"\nNumber of Episodes: "+getEpisodes()+
"\nRunning Time: "+getRunningTime()+"\nLead Actor/Actress: "+
getLead()+"\n";
}
}


//Driver class that demonstartes Inheritance
public class Inheritance{
//driver function
public static void main(String[] args) {
//object of class Movies using over loaded constructor
Movies m = new Movies("Extraction", "24 April, 2020","Acton/Thriller",
"AGBO", "Netflix" );
//object of class TvShow using overloaded constructor
TvShow t = new TvShow("Friends", "Sitcom", "22 September, 1994",10, "NBC",
"20-22 minutes");

//object of MiniSeries using default constructor and setters
MiniSeries s = new MiniSeries();
s.setTitle("Chernobyl");
s.setGenre("Historical Drama/ Tragedy");
s.setEpisodes(5);
s.setRunningTime("59-72 minutes");
s.setLead("Jared Harris, Stellan Skarsgård, Emily Watson, Paul Ritter");

//Printing number of objects in Video Library
System.out.println("Number of objects in Video Library: "+ VideoContent.numberOfObjects);
//Printing details about each object
System.out.println(m);
System.out.println(t);
System.out.println(s);
}
}
------------------------------------------------------------------------------------------------------------------------------------

Note: Comments have been added for better understanding.

Output of the code:

----------------------------------------------------------------------------------------------------------------------------------------------------------

Hope this helps. If you like the answer, please upvote. Cheers!!

Know the answer?
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
Similar Questions
Java code Problem 1. Create a Point class to hold x and y values for a...
Java code Problem 1. Create a Point class to hold x and y values for a point. Create methods show(), add() and subtract() to display the Point x and y values, and add and subtract point coordinates. Tip: Keep x and y separate in the calculation. Create another class Shape, which will form the basis of a set of shapes. The Shape class will contain default functions to calculate area and circumference of the shape, and provide the coordinates (Points)...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and packages: - variable names start with a lowercase character for the first word and uppercase for every other word - classes start with an uppercase character of every word - packages use only lowercase characters - methods start with a lowercase character for the first word and uppercase for every other word Java Programming COMP-228 Exercise #1: [5 marks] Write a Java application using...
We encourage you to work in pairs for this challenge to create a Student class with...
We encourage you to work in pairs for this challenge to create a Student class with constructors. First, brainstorm in pairs to do the Object-Oriented Design for a Student class. What data should we store about Students? Come up with at least 4 different instance variables. What are the data types for the instance variables? Write a Student class below that has your 4 instance variables and write at least 3 different constructors: one that has no parameters and initializes...
Design a Java class named Polygon that contains:  A private int data field named numSides...
Design a Java class named Polygon that contains:  A private int data field named numSides that defines the number of sides of the polygon. The default value should be 4.  A private double data field named sideLength that defines the length of each side. The default value should be 5.0.  A private double data field named xCoord that defines the x-coordinate of the center of the polygon. The default value should be 0.0.  A private double...
Create a currency class, up to 5 individual currencies, with four attributes - currency name, whole...
Create a currency class, up to 5 individual currencies, with four attributes - currency name, whole parts and fractional parts and fractional's name such that 100 fractional parts equals 1 whole part, e.g. Pound, 1, 55, pence or Euro, 3, 33, cent. Define overloaded operators to add or subtract different currency objects - care should be taken that you can only perform these operation on objects of the same currency. Also, take care that fractional parts roll into whole parts....
IN JAVA Inheritance Using super in the constructor Using super in the method Method overriding Write...
IN JAVA Inheritance Using super in the constructor Using super in the method Method overriding Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method in it. The following characteristics should be used: make, weight, height, length, maxSpeed, numberDoors, maxPassenges, isConvertable, numberSeats, maxWeightLoad, and numberAxels. Characteristics that are applicable to all vehicles should be instance variables in the Vehicle class. The others should be in the class(s) where they belong. Class vehicle should have...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a name, an address, and a hire date. A name consists of a first name and a last name. An address consists of a street, a city, a state (2 characters), and a 5-digit zip code. A date consists of an integer month, day and year. All fields are required to be non-blank. The Date fields should be reasonably valid values (ex. month 1-12, day...
1. Circle: Implement a Java class with the name Circle. It should be in the package...
1. Circle: Implement a Java class with the name Circle. It should be in the package edu.gcccd.csis. The class has two private instance variables: radius (of the type double) and color (of the type String). The class also has a private static variable: numOfCircles (of the type long) which at all times will keep track of the number of Circle objects that were instantiated. Construction: A constructor that constructs a circle with the given color and sets the radius to...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes and methods. Purpose: The purpose of this challenge is to provide experience creating a class and working with OO concepts in Python 3. Requirements: Write a class in Python 3 named Animal that has the following attributes and methods and is saved in the file Animal.py. Attributes __animal_type is a hidden attribute used to indicate the animal’s type. For example: gecko, walrus, tiger, etc....
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT