Question

In: Computer Science

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

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.

Solutions

Expert Solution

Solution

In the code common attributes is taken as parent class which is superclass

superclass get inherited three times by movies, tvshows , miniseries

superclass has two attributes which is common in almost all three derived class which is title and genre

movies attributes are following in the data types are

  1. title
  2. genre
  3. release_date
  4. studio
  5. streamingsource

TV_shows attributes are following :-

  1.   tile
  2. genre
  3.     date_of_first_series;
  4.    no_of-series;
  5.     network;
  6.     running_time;

similarly minseries attributes are :-

  1. title
  2. genre
  3. no_of_running_time;
  4. lead_actor;

tostringmethod()

toString() method returns the string representation of the object.

java compiler internally invokes the toString() method on the object.

overriding the toString() method, returns the desired output, it can be the state of an object etc. depends on your implementation.

  1. //--------------------
    //file name : result.java
    //----------------------
    class superclass
    {
    
      public  String title;
      public  String genre;
    }
    
    class movies extends superclass
    {
    public String release_date;
    public   String studio;
    public   String streamingsource;
    movies(String title,String genre, String release_date,String studio, String streamingsource)
    {
      this.title=title;
      this.genre=genre;
      this.release_date=release_date;
      this.studio=studio;
      this.streamingsource=streamingsource;
    }
    public String toString(){//overriding the toString() method  
      return title+" "+genre+" "+release_date+" "+studio+" "+streamingsource;  
    }
    }
    class tvshows extends superclass
    {
       
       public   String date_of_first_series;
       public   int  no_of_series;
       public   String network;
       public   String running_time;
        tvshows(String title,String genre,String date1,int num, String network,String running_time)
       {
        this.title=title;
        this.genre=genre;
        this.date_of_first_series=date1;
        this.no_of_series=num;
        this.network=network;
        this.running_time=running_time;
       }
    public String toString(){//overriding the toString() method  
      return date_of_first_series+" "+no_of_series+" "+network+" "+running_time;  
    }
    
    }
    class mini_series extends superclass 
    {
         public int no_of_running_time;
         public String lead_actor;
         mini_series(String title,String genre, int no_of_running_time,String lead_actor)
         {
          this.title=title;
          this.genre=genre;
          this.no_of_running_time=no_of_running_time;
          this.lead_actor=lead_actor;
         }
          public String toString(){
          //overriding the toString() method  
         return title+" "+genre+" "+no_of_running_time+" "+lead_actor;  
         }
    }
    class result
    {
        public static void main(String  args[])
        {
        movies mv1 =new movies("Harley Quinn","Action","12/7/2005","Dreamburgs","Netflix");
        tvshows tv1=new tvshows("TVshows","Comedy","12/05/1998",3,"hello","56 minutes");
        mini_series ms1=new mini_series("Minishows","Drama",5,"Leonardo ");
        System.out.println("Movies Details ::::");
        System.out.println("title, Genre, release_date, studio, streaming source");
        System.out.println(mv1);
        System.out.println("\nTV Details ::::");
        System.out.println("title, Genre, number in series, network ,running_time ");
        System.out.println(tv1);
        System.out.println("\nMini_series ::::");
        System.out.println("title, Genre, running_time, lead_actor ");
        System.out.println(ms1);
        }
    }
    
    

    //output

all output has done through tostring method which has been shown in question

STEP 1: save file result.java

STEP2 : for compiling type javac result.java

STEP3 : for run to the file type java result

then it will print the desired output as you wants


Related Solutions

Lab Objectives Be able to declare a new class Be able to write a constructor Be...
Lab Objectives Be able to declare a new class Be able to write a constructor Be able to write instance methods that return a value Be able to write instance methods that take arguments Be able to instantiate an object Be able to use calls to instance methods to access and change the state of an object Introduction Everyone is familiar with a television. It is the object we are going to create in this lab. First we need a...
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score...
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score (int). A constructor expects a name as a parameter. A method getLevel to get the level(char) of the student. score level table: A: score >= 90 B: score >= 80 and < 90 C: score >= 60 and < 80 D: score < 60 Example:          Student student = new Student("Zack"); student.score = 10; student.getLevel(); // should be 'D'. student.score = 60; student.getLevel(); //...
How to write a Java program that has a base class with methods and attributes, subclasses...
How to write a Java program that has a base class with methods and attributes, subclasses with methods and attributes. Please use any example you'd like.
A researcher was interested in the effects of different study methods on learning, among a class...
A researcher was interested in the effects of different study methods on learning, among a class of children. Following one of three methods, 6 students were divided into groups. Method 1 (book alone) Method 2 (borrowing notes) Method 3 (taking notes) 10 12 18 8 6 40 15 30 35 26 24 29 28 18 30 12 13 25 Using manual computation, perform the appropriate hypothesis test at α = 0.01
Task1: Write a class DynArr that represents an array data structure. Here are the attributes (data)...
Task1: Write a class DynArr that represents an array data structure. Here are the attributes (data) of the class (note - fields of the objects should be marked as private)” INITIAL_SIZE: the initial size of the array = 10; _innerArr: an array of integers _growthFactor: the factor by which to resize the array with to become bigger. _lastIndex: an index on the last element in the array. The class will have the constructor public DynArr() that initialzes an array of...
Code in C# Part 1 Build a Series class that has the following attributes and behaviors:...
Code in C# Part 1 Build a Series class that has the following attributes and behaviors: Attributes 1.) A name -- this can be any string value (i.e. “Firefly”) 2.) A number of episodes -- this can be any non-negative integer value 3.) An episode length -- this can be a double value, in hours, representing the length of an episode (i.e. 0.5 for a half-hour episode, or 0.37 for a 23 minute episode) 4.) A forKids attribute that holds...
PLEASE PROVIDE COMMENTS TO BE ABLE TO UNDERSTAND CODE C++ Inventory Class Create an inventory class....
PLEASE PROVIDE COMMENTS TO BE ABLE TO UNDERSTAND CODE C++ Inventory Class Create an inventory class. The class will have the following data members, const int size = 100; int no_of_products; // the total number of products in the inventory. char name_array[size][15] ; // stores name of products double array [size][2]; // In the first column quantity of the product and in the second column the price per item of the product is stored. name_array stores the name of products,...
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet...
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet will be a simple class consisting of three fields: name: string representing the name of a planet, such as “Mars” madeOf: string representing the main element of the planet alienPopulation: int representing if the number of aliens living on the planet Your Planet class should have the following methods: Planet(name, madeOf, alienPopulation) // Constructor getName(): string // Returns a planet’s name getMadeOf(): String //...
Write a Class called Module with the following attributes: module code, module name, list of lecturers...
Write a Class called Module with the following attributes: module code, module name, list of lecturers for the module (some modules may have more than one lecturer – we only want to store their names), number of lecture hours, and module description. Create a parameterised (with parameters for all of the class attributes) and a non-parameterised constructor, and have the accessor and mutator methods for each attribute including a toString method. Write a class Student with the following attributes: student...
Lesson Objectives :By the end of this lesson, students should be able to: Be able to...
Lesson Objectives :By the end of this lesson, students should be able to: Be able to discuss the history of labor unions. Explain some of the reasons for a decline in union membership over the past sixty years. Be able to explain the process of unionization and laws that relate to unionization. Be able to describe the process of collective bargaining. Understand the types of bargaining issues and the rights of management. Discuss some strategies when working with unions. Be...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT