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
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....
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...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String[] students = new String[1];     private int numberOfStudents;     public COurseCom666(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public void addStudent(String student) {         if (numberOfStudents == students.length) {             String[] a = new String[students.length + 1];            ...
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...
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);...
Here is my java code, I keep getting this error and I do not know how...
Here is my java code, I keep getting this error and I do not know how to fix it: PigLatin.java:3: error: class Main is public, should be declared in a file named Main.java public class Main { ^ import java.io.*; public class Main { private static BufferedReader buf = new BufferedReader( new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { String english = getString(); String translated = translate(english); System.out.println(translated); } private static String translate(String s) { String latin =...
[Java] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
Hello. I have an assignment that is completed minus one thing, I can't get the resize...
Hello. I have an assignment that is completed minus one thing, I can't get the resize method in Circle class to actually resize the circle in my TestCircle claass. Can someone look and fix it? I would appreciate it! If you dont mind leaving acomment either in the answer or just // in the code on what I'm doing wrong to cause it to not work. That's all I've got. Just a simple revision and edit to make the resize...