Question

Based on Movie package example, you will create a package about your favorite TV series and...

Based on Movie package example, you will create a package about your favorite TV series and provide the plot()

Readme.txt: Explain how you apply polymorphism in your program

package Movie;

public class MovieTester {
public static void main(String[] args) {

for(int i = 1; i < 11; i++){
Movie movie = randomMovie();
System.out.println("Movie # " + i + ": " + movie.getTitle() + ", Genre: " + movie.getGenre() + '\n'
+"Plot: " + movie.plot());
}

}

public static Movie randomMovie(){
int randomNumber = (int)(Math.random() * 5) + 1; //1 and 5

System.out.println("Random number is going to be generated and it is " + randomNumber);

switch(randomNumber){
case 1: return new Borat();
case 2: return new Inception();
case 3: return new JohnWick();
case 4: return new Parasite();
case 5: return new Shrek();
}

return null;
}
}

class Movie{

private String title;
private String genre;
private String rating;
private int year;
private int length; //minute

public Movie(String title, String genre, String rating, int year, int length) {
this.title = title;
this.genre = genre;
this.rating = rating;
this.year = year;
this.length = length;
}

public String getTitle() {
return title;
}

public String getGenre() {
return genre;
}

public String getRating() {
return rating;
}

public int getYear() {
return year;
}

public int getLength() {
return length;
}

public String plot(){
return "No plot yet provided";
}
}

//Shrek, JohnWick, Inception, Borat, Parasite

class Shrek extends Movie{

public Shrek(){
super("Shrek","Animation","R",1991,120);
}
@Override
public String plot(){
return "To save Fiona.";
}


}

class JohnWick extends Movie{


public JohnWick(){
super("John Wick","Action","R",2000,120);
}

@Override
public String plot(){
return "To revenge";
}

}

class Inception extends Movie{

public Inception(){
super("Inception", "Thriller", "PG",1996, 150);
}

@Override
public String plot(){
return "To chasing.";
}

}

class Borat extends Movie{

public Borat(){
super("Borat", "Comedy", "R", 2020,120);
}

@Override
public String plot(){
return "Trying to find Pamela Anderson.";
}


}

class Parasite extends Movie{

public Parasite(){
super("Parasite", "Horror", "R", 2019, 120);
}

@Override
public String plot(){
return "About three family";
}

}

Homework Answers

Answer #1

You already have a code where multiple movies with their plots are given.. So i will only focus my answer on below:

Explain how you apply polymorphism in your program

The movie class is the base class, where each of the specifc movies(child classes) such as Parasite, Inception etc, they extend the original movie class. The plot method in base movie class says "No plot yet provided", while each of the child movie classes override this method and provide their own specific plots..

At run time with dynamic polymorphism, on the movie object it is actually decided which plot method should be called.. As the child classes provide their implementation, hence instead of base class, child class methods are actually invoked and thus the plots are printed..

please let me know if anything is not clear in my answer or any issues. Thanks
please upvote if possible.

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
This assignment is an individual assignment. For Questions 1-3: consider the following code: public class A...
This assignment is an individual assignment. For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B()...
Create a class called MovieReducerLength that implements MediaReducer. Implement a reducer that takes a movie list...
Create a class called MovieReducerLength that implements MediaReducer. Implement a reducer that takes a movie list and a String length, then return a String that contains all the movies that have a name of the given length. Files Given: Movie.java public class Movie extends Media { public Movie(String name, int year, String genre) { super(name, year, genre); } public String getEra() { if (getYear() >= 2000) { return "New Millennium Era"; } else if (getYear() >= 1977) { return "Modern...
Determine how all of your classes are related, and create a complete UML class diagram representing...
Determine how all of your classes are related, and create a complete UML class diagram representing your class structure. Don't forget to include the appropriate relationships between the classes. GameDriver import java.util.Scanner; public class GameDriver { Scanner in = new Scanner(System.in); public static void main(String[] args) { Move move1 = new Move("Vine Whip", "Grass", 45, 1.0f); Move move2 = new Move("Tackle", "Normal", 50, 1.0f); Move move3 = new Move("Take Down", "Normal", 90, 0.85f); Move move4 = new Move("Razor Leaf", "Grass",...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields,...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields...
Java: ModifyStudentList.javato use anArrayListinstead of an array In StudentList.java, create two new public methods: The addStudent...
Java: ModifyStudentList.javato use anArrayListinstead of an array In StudentList.java, create two new public methods: The addStudent method should have one parameter of type Student and should add the given Student to the StudentList. The removeStudent method should have one parameter of type String. The String is the email of the student to be removed from the StudentList. In Assign5Test.java do the following: Create a new StudentList containing 3 students. Print the info of all the Students in the StudentList using...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){    strName = " ";    strSalary = "$0";    } public Employee(String Name, String Salary){    strName = Name;    strSalary = Salary;    } public void setName(String Name){    strName = Name;    } public void setSalary(String Salary){    strSalary = Salary;    } public String getName(){    return strName;    } public String getSalary(){    return strSalary;    } public String...
This is the java code that I have, but i cannot get the output that I...
This is the java code that I have, but i cannot get the output that I want out of it. i want my output to print the full String Form i stead of just the first letter, and and also print what character is at the specific index instead of leaving it empty. and at the end for Replaced String i want to print both string form one and two with the replaced letters instead if just printing the first...
import java.util.Scanner; public class FindMinLength { public static int minLength(String[] array) { int minLength = array[0].length();...
import java.util.Scanner; public class FindMinLength { public static int minLength(String[] array) { int minLength = array[0].length(); for (int i = 0; i < array.length; i++) { if (array[i].length() < minLength) minLength = array[i].length(); } return minLength; } public static void main(String[] args) { Scanner in = new Scanner(System.in); String[] strings = new String[50]; for (int i = 0; i < strings.length; i++) { System.out.print("Enter string " + (i + 1) + ": "); strings[i] = in.nextLine(); } System.out.println("Length of smallest...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*;...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener {     int count;     JButton button;     Clicker() {         super("Click Me");         button = new JButton(String.valueOf(count));         add(button);         button.addActionListener(this);         setSize(200,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     }     public void actionPerformed(ActionEvent e) {         count++;         button.setText(String.valueOf(count));     }     public static void main(String[] args) { new Clicker(); } } a. add(button);...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT