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)...
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 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,...
Classes/ Objects(programming language java ) in software (ATOM) Write a Dice class with three data fields...
Classes/ Objects(programming language java ) in software (ATOM) Write a Dice class with three data fields and appropriate types and permissions diceType numSides sideUp The class should have A 0 argument (default) constructor default values are diceType: d6, numSides: 6, sideUp: randomValue 1 argument constructor for the number of sides default values are diceType: d{numSides}, sideUp: randomValue 2 argument constructor for the number of sides and the diceType appropriate accessors and mutators *theoretical question: can you change the number of...
Homework 3 Before attempting this project, be sure you have completed all of the reading assignments,...
Homework 3 Before attempting this project, be sure you have completed all of the reading assignments, hands-on labs, discussions, and assignments to date. Create a Java class named HeadPhone to represent a headphone set. The class contains:  Three constants named LOW, MEDIUM and HIGH with values of 1, 2 and 3 to denote the headphone volume.  A private int data field named volume that specifies the volume of the headphone. The default volume is MEDIUM.  A private...
6) Consider the following class descriptions for objects in a video game: An NPC (non-player character)...
6) Consider the following class descriptions for objects in a video game: An NPC (non-player character) in a video game has some basic data that belongs to all entities in a game. All NPCs have a name, which is a String, health, which is an integer, and a description, which is a String. NPCs have accessor methods for each of their instance variables. NPCs also have an act() method, which is void; however, since there are no true NPCs in...
6) Consider the following class descriptions for objects in a video game: An NPC (non-player character)...
6) Consider the following class descriptions for objects in a video game: An NPC (non-player character) in a video game has some basic data that belongs to all entities in a game. All NPCs have a name, which is a String, health, which is an integer, and a description, which is a String. NPCs have accessor methods for each of their instance variables. NPCs also have an act() method, which is void; however, since there are no true NPCs in...
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational...
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational numbers in a mixed number format (integer part and a fraction part). Details and Requirements Your class must allow for storage of rational numbers in a mixed number format. Remember that a mixed number consists of an integer part and a fraction part (like 3 1/2 – “three and one-half”). The Mixed class must allow for both positive and negative mixed number values. A...
The main goal is to implement two recursive methods, each is built to manipulate linked data...
The main goal is to implement two recursive methods, each is built to manipulate linked data structures. To host these methods you also have to define two utterly simplified node classes. 1.) Add a class named BinaryNode to the project. This class supports the linked representation of binary trees. However, for the BinaryNode class Generic implementation not needed, the nodes will store integer values The standard methods will not be needed in this exercise except the constructor 2.) Add a...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT