In: Computer Science
Language: Java
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.
All required variables are members of the class. Appropriate use of access specifiers. Encapsulation is implemented with setters and getters. Code is well structured and commented. Code meets standard Java conventions.
There is a default (no-arg) constructor, and an overloaded constructor for each video type. Objects created all have appropriate data content. A static variable is implemented and correctly counts objects created.
Methods are established in the class for all appropriate setters and getters. Inheritance is properly demonstrated with appropriate attributes, methods, and object instantiation.
The VideoLibrary class properly creates all the required objects and displays the entire video library with the number of items and all the data content in a nicely formatted output.
SOLUTION:
Short Summary:
Provided the source code and sample output as per the
requirements.
*************Please upvote the answer and appreciate our
time.***********
SOURCE CODE:
VideoContent.java:
/**
*
* VideoContent parent class
*/
public class VideoContent {
// attributes of parent class
String title;
String genre;
static int counter = 0;
public VideoContent() {
title = "";
genre = "";
counter++;
}
public VideoContent(String title, String genre) {
this.title = title;
this.genre = genre;
VideoContent.counter++;
}
// getter of title
public String getTitle() {
return title;
}
// setter of title
public void setTitle(String title) {
this.title = title;
}
// getter of genre
public String getGenre() {
return genre;
}
// setter of genre
public void setGenre(String genre) {
this.genre = genre;
}
// getter of counter
public static int getCounter() {
return counter;
}
@Override
public String toString() {
return "Title : " + title + "\nGenre : " + genre;
}
}
TvShow.java:
/**
*
* TvShows class
*/
public class TvShow extends VideoContent {
String firstEpisodeDate;
int seasonsNum;
String network;
String runningTime;
public TvShow() {
super();
firstEpisodeDate = "";
seasonsNum = 0;
network = "";
runningTime = "";
}
public TvShow(String title, String genre, String firstEpisodeDate, int seasonsNum, String network, String runningTime) {
super(title, genre);
this.firstEpisodeDate = firstEpisodeDate;
this.seasonsNum = seasonsNum;
this.network = network;
this.runningTime = runningTime;
}
// getters and setters of TvShow
public String getFirstEpisodeDate() {
return firstEpisodeDate;
}
public void setFirstEpisodeDate(String firstEpisodeDate) {
this.firstEpisodeDate = firstEpisodeDate;
}
public int getSeasonsNum() {
return seasonsNum;
}
public void setSeasonsNum(int seasonsNum) {
this.seasonsNum = seasonsNum;
}
public String getNetwork() {
return network;
}
public void setNetwork(String network) {
this.network = network;
}
public String getRunningTime() {
return runningTime;
}
public void setRunningTime(String runningTime) {
this.runningTime = runningTime;
}
@Override
public String toString() {
String resultString = super.toString();
resultString += "\nFirst Episode Date : " + firstEpisodeDate + "\nNumber of Seasons :"
+ seasonsNum + "\nNetwork : " + network + "\nRunning Time : " + runningTime;
return resultString;
}
}
Movies.java:
/**
*
* Movies class
*/
public class Movies extends VideoContent {
String releaseDate;
String studio;
String streamingSource;
public Movies() {
super();
releaseDate = "";
studio = "";
streamingSource = "";
}
public Movies(String title, String genre, String releaseDate, String studio, String streamingSource) {
super(title, genre);
this.releaseDate = releaseDate;
this.studio = studio;
this.streamingSource = streamingSource;
}
// getters of releaseDate
public String getReleaseDate() {
return releaseDate;
}
// setters of releaseDate
public void setReleaseDate(String releaseDate) {
this.releaseDate = releaseDate;
}
// getters of studio
public String getStudio() {
return studio;
}
// setters of studio
public void setStudio(String studio) {
this.studio = studio;
}
// getters of streamingsource
public String getStreamingSource() {
return streamingSource;
}
// setters of streamingsource
public void setStreamingSource(String streamingSource) {
this.streamingSource = streamingSource;
}
@Override
public String toString() {
String resultString = super.toString();
resultString += "\nRelease Date : " + releaseDate + "\nStudio : " + studio + "\nStreaming Source : " + streamingSource;
return resultString;
}
}
MiniSeries.java:
/**
*
* MiniSeries class
*/
public class MiniSeries extends VideoContent {
// attributes of MiniSeries class
int episodesNum;
String runningTime;
String leadActor;
public MiniSeries() {
super();
episodesNum = 0;
runningTime = "";
leadActor = "";
}
public MiniSeries(String title, String genre, int episodesNum, String runningTime, String leadActor) {
super(title, genre);
this.episodesNum = episodesNum;
this.runningTime = runningTime;
this.leadActor = leadActor;
}
// getters and setters of MiniSeries
public int getEpisodesNum() {
return episodesNum;
}
public void setEpisodesNum(int episodesNum) {
this.episodesNum = episodesNum;
}
public String getRunningTime() {
return runningTime;
}
public void setRunningTime(String runningTime) {
this.runningTime = runningTime;
}
public String getLeadActor() {
return leadActor;
}
public void setLeadActor(String leadActor) {
this.leadActor = leadActor;
}
@Override
public String toString() {
String resultString = super.toString();
resultString += "\nNumber of episodes : " + episodesNum + "\nRunning Time : " + runningTime + "\nLead Actor :" + leadActor;
return resultString;
}
}
VideoContentDriver.java:
/**
*
* Main Driver class
*/
public class VideoContentDriver {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// create object for TvShow using default constructor
TvShow tvShow = new TvShow();
// using setters
tvShow.setTitle("Dark");
tvShow.setGenre("Science Fiction thiller");
tvShow.setFirstEpisodeDate("December 1, 2017");
tvShow.setSeasonsNum(5);
tvShow.setNetwork("flix");
tvShow.setRunningTime("44minutes");
// create object for TvShow using paramterized constructor
TvShow tvShow1 = new TvShow("Sherlock Holmes", "Fictional ", "April 24, 1984", 7, "flix", "55 min");
// create object for Movies using default constructor
Movies movies = new Movies();
movies.setTitle("Pink");
movies.setGenre("Crime");
movies.setReleaseDate("September 16, 2016");
movies.setStudio("Zee studio");
movies.setStreamingSource("NetFlix");
// create object for TvShow using paramterized constructor
Movies movies1 = new Movies("Black Panther", "Action Adventure", "February 16, 2018", "Marvel Studios", "Prime");
MiniSeries miniSeries = new MiniSeries();
miniSeries.setTitle("Chernobyl");
miniSeries.setGenre("Historical drama ");
miniSeries.setEpisodesNum(5);
miniSeries.setRunningTime("70 minutes ");
miniSeries.setLeadActor("Jared Harris ");
MiniSeries miniSeries1 = new MiniSeries("When They See Us", "Crime", 4, "50 mins", "Asante Blackk");
System.out.println("Number of items: " + VideoContent.getCounter());
// display result
String tvshowResult = tvShow.toString();
System.out.println("\n***** TvShow Result ****\n" + tvshowResult);
// display result
String tvshowResult1 = tvShow1.toString();
System.out.println("\n***** TvShow Result ****\n" + tvshowResult1);
// display result
String moviesResult = movies.toString();
System.out.println("\n***** Movies Result ****\n" + moviesResult);
// display result
String moviesResult1 = movies1.toString();
System.out.println("\n***** Movies Result ****\n" + moviesResult1);
// display result
String miniResult = miniSeries.toString();
System.out.println("\n***** Movies Result ****\n" + miniResult);
// display result
String miniResult1 = miniSeries1.toString();
System.out.println("\n***** Movies Result ****\n" + miniResult1);
}
}
SAMPLE OUTPUT: