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

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(); //...
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++ 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...
Add code (see below for details) to the methods "set" and "get" in the following class,...
Add code (see below for details) to the methods "set" and "get" in the following class, ArrayTen.java, so that these two methods catch the exception java.lang.ArrayIndexOutOfBoundsException if an illegal index is used, and in turn throw java.lang.IndexOutOfBoundsException instead. Modify the "main" method to catch java.lang.IndexOutOfBoundsException and, when such an exception is caught, print the exception as well as the stack trace. public class ArrayTen { private String myData[] = new String[10]; public void set(int index, String value) { myData[index] =...
java code Add the following methods to the LinkedQueue class, and create a test driver for...
java code Add the following methods to the LinkedQueue class, and create a test driver for each to show that they work correctly. In order to practice your linked list cod- ing skills, code each of these methods by accessing the internal variables of the LinkedQueue, not by calling the previously de?ined public methods of the class. String toString() creates and returns a string that correctly represents the current queue. Such a method could prove useful for testing and debugging...
Submit a document with methods for an automobile class, and pseudo code indicating functionality of each...
Submit a document with methods for an automobile class, and pseudo code indicating functionality of each method. Example: public String RemoveVehicle(String autoMake, String autoModel, String autoColor, int autoYear) If values entered match values stored in private variables remove vehicle information else return message indicating mismatch
Serial Case C6-72Calculate and compare cost estimates using high-low and regression methods (Learning Objectives 4 &...
Serial Case C6-72Calculate and compare cost estimates using high-low and regression methods (Learning Objectives 4 & 5) This case is a continuation of the Caesars Entertainment Corporation serial case that began in Chapter 1. Refer to the introductory story in Chapter 1, here for additional background. (The components of the Caesars serial case can be completed in any order.) Caesar Entertainment Corporation’s Form 10-K contains a variety of data in addition to financial statements. Below is a list that contains...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT