SlideShare a Scribd company logo
Write a Java program that mimics the framework for an online movie information system similar
to IMDB written in Java. Create an abstract base class, two subclasses, and one interface to
provide basic functionality for the system. Use the provided UML, the class descriptions, and the
test output to determine the proper behavior for your classes.
Create an interface Rateable that: Provides a method vote(int numVotes, int voteScore).
Create an abstract class Movie that: Implements the Rateable and Comparable interfaces.
Provides the data fields: title, releaseYear, genre, numVotes, and voteScore. Provides four
constructors: o Default, no-arg constructor o Three convenience constructors that allow as
parameters: the title the title and releaseYear the title, releaseYear, and genre. Provides an
abstract getInfo() method. Provides a concrete toString() method that returns the only movie
title. Provides a concrete getRating() method that returns: o -1 if numVotes is 0, o
voteScore/numVotes otherwise. Implements the Rateable interface’s vote() method by
increasing the existing values of numVotes and voteScore by the amount passed in the
appropriate parameter. Implements the Comparable interface’s compareTo() method by
comparing ratings. Movies should be sorted in descending order, meaning that a higher rating
should be considered “less than” a lower rating.
Create a concrete class Horror that: Automatically sets the genre to Horror in its constructors.
Adds a data attribute for number of deaths, numOfDeaths, with the appropriate getter/setter
methods.
2
Provides a getInfo() method that returns “title, genre, releaseYear (rating): numDeaths deaths”
with the appropriate values. o Detects if it receives a -1 from getRating() and uses “No ratings”
as the rating. o To pass LiveLab’s auto-grader, make sure ratings are limited to one decimal
place (see documentation on using String.format() which works similar to System.out.printf()).
Create a concrete class Comedy that: Automatically sets the genre to Comedy in its
constructors. Adds a data attribute, hasProfanity, to indicate whether there is profanity in the
film with the appropriate getter/setter methods. Provides a getInfo() method that returns “title,
genre, releaseYear (rating): Profanity/No Profanity” with the appropriate values. o Detects if it
receives a -1 from getRating() and use “No ratings” as the rating. o To pass LiveLab’s auto-
grader, make sure ratings are limited to one decimal place (see documentation on using
String.format() which works similar to System.out.printf()).
NOTE: Movie, Horror, and Comedy should provide all of the appropriate accessor/mutator
methods for their data fields. For brevity, these are not included in the UML.
Main method Create the horror movies: o A Nightmare on Elm Street, 1984, 4 deaths o Final
Destination 5, 2011, 94 deaths1 o Saw, 2004, 6 deaths Create the comedy movies: o Napoleon
Dynamite, 2004, no profanity o Keeping Up with the Joneses, 2016, profanity o Uncle Buck,
1989, profanity
Use the vote() method to assign votes to the respective movies: (# votes - total vote score) o A
Nightmare on Elm Street: 151,963 – 1,139,723 o Final Destination 5: 84,907 – 500,951 o Saw:
303,578 – 2,337,551 o Napoleon Dynamite: 163,240 – 1,126,356 o Uncle Buck: 64,031 –
448,217
Create an Array of type Movie and populate it with all of the created movies. Do not create
them in sorted order, let the sort method handle that. Sort the array using the
java.util.Arrays.sort() method. Using a loop, print the results of the getInfo() call for each movies
in the sorted array. 1 http://finaldestination.wikia.com/wiki/List_of_deaths
3
Simplified UML
Test Output Saw, Horror, 2004 (7.7): 6 deaths A Nightmare on Elm Street, Horror, 1984 (7.5): 4
deaths Napoleon Dynamite, Comedy, 2004 (6.9): No Profanity Uncle Buck, Comedy, 1989 (6.9):
Profanity Final Destination 5, Horror, 2011 (5.9): 94 deaths Keeping Up with the Joneses,
Comedy, 2016 (No ratings): Profanity
Solution
PROGRAM CODE:
Rateable.java
package movies;
public interface Rateable {
//abstract method for the rateable class
public void vote(int numVotes, int voteScore);
}
Movie.java
package movies;
public abstract class Movie implements Rateable, Comparable{
// Data fields for the class
String title;
int releaseYear;
String genre;
int numVotes;
int voteScore;
// Default constructor
Movie()
{
title = "";
genre = "";
}
//Parameterized Constructors
Movie(String title)
{
this.title = title;
}
Movie(String title, int releaseYear)
{
this.title = title;
this.releaseYear = releaseYear;
}
Movie(String title, int releaseYear, String genre)
{
this.title = title;
this.releaseYear = releaseYear;
this.genre = genre;
}
//setters and getters
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getReleaseYear() {
return releaseYear;
}
public void setReleaseYear(int releaseYear) {
this.releaseYear = releaseYear;
}
public String getGenre() {
return genre;
}
public void setGenre(String genre) {
this.genre = genre;
}
public int getNumVotes() {
return numVotes;
}
public void setNumVotes(int numVotes) {
this.numVotes = numVotes;
}
public int getVoteScore() {
return voteScore;
}
public void setVoteScore(int voteScore) {
this.voteScore = voteScore;
}
// abstract method
public abstract String getInfo();
// toString() to return the movie title
public String toString()
{
return this.title;
}
//getRating() method to calculate rating
public int getRating()
{
if(this.numVotes > 0)
return -1;
else
return this.voteScore/numVotes;
}
// method to define from Comparable interface
@Override
public int compareTo(Movie movie) {
if(this.getRating() == movie.getRating())
return 0;
else if(this.getRating() > movie.getRating())
return 1;
else
return -1;
}
//method to define from Rateable interface
@Override
public void vote(int numVotes, int voteScore) {
this.numVotes = numVotes;
this.voteScore = voteScore;
}
}
Horror.java
package movies;
public class Horror extends Movie{
int numOfDeaths;
String genre;
//Setting the genre to Horror in default comstructor
public Horror() {
this.genre = "Horror";
}
//setter and getter
public int getNumOfDeaths() {
return numOfDeaths;
}
public void setNumOfDeaths(int numOfDeaths) {
this.numOfDeaths = numOfDeaths;
}
// Implementing the abstract method
public String getInfo()
{
String rating = this.getRating() < 0? "No ratings": String.valueOf(this.getRating());
return this.title + "," + this.genre + "," + this.releaseYear + "(" + rating + "):" +
this.numOfDeaths +"deaths";
}
}
Comedy.java
package movies;
public class Comedy extends Movie{
boolean hasProfanity;
//Setters and getters
public boolean isHasProfanity() {
return hasProfanity;
}
public void setHasProfanity(boolean hasProfanity) {
this.hasProfanity = hasProfanity;
}
public Comedy()
{
this.genre = "Comedy";
}
@Override
public String getInfo() {
String rating = this.getRating() < 0? "No ratings": String.valueOf(this.getRating()); // using
ternary operator to check if value is less than 0
String profanity = this.hasProfanity? "Profanity" : "No Profanity";
// using ternary operator to check if profanity is true or false and setting string value based
on that
return this.title + "," + this.genre + "," + this.releaseYear + "(" + rating + "):" +
profanity;
}
}
MainClass.java
package movies;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import javax.sound.midi.ControllerEventListener;
public class MainClass {
public static void main(String[] args) {
//creating objects for Horror and Comedy and adding data
Horror horror = new Horror();
horror.setTitle("A Nightmare on Elm Street");
horror.setReleaseYear(1984);
horror.setNumOfDeaths(4);
Horror horror2 = new Horror();
horror2.setTitle("Final Destination 5");
horror2.setReleaseYear(2011);
horror2.setNumOfDeaths(94);
Horror horror3= new Horror();
horror3.setTitle("Saw");
horror3.setReleaseYear(2004);
horror3.setNumOfDeaths(6);
Comedy comedy1 = new Comedy();
comedy1.setTitle("Napolean Dynamite");
comedy1.setReleaseYear(2004);
comedy1.setHasProfanity(false);
Comedy comedy2 = new Comedy();
comedy2.setTitle("Keeping Up with the Joneses");
comedy2.setReleaseYear(2016);
comedy2.setHasProfanity(true);
Comedy comedy3 = new Comedy();
comedy3.setTitle("Uncle Buck");
comedy3.setReleaseYear(1989);
comedy3.setHasProfanity(true);
horror.vote(151963, 1139723);
horror2.vote(84907, 500951);
horror3.vote(303578, 2337551);
comedy1.vote(163240, 1126356);
comedy3.vote(64031, 448217);
//creating an arraylist and adding all the movies into it
ArrayList movieList = new ArrayList<>();
movieList.add(horror);
movieList.add(horror2);
movieList.add(horror3);
movieList.add(comedy1);
movieList.add(comedy2);
movieList.add(comedy3);
//creating an arraylist and adding all the movies into it
Movie[] movies = new Movie[6];
movies[0] = horror;
movies[1] = horror2;
movies[2] = horror3;
movies[3] = comedy1;
movies[4] = comedy2;
movies[5] = comedy3;
//Sorting the arraylist
Arrays.sort(movies);
//printing the arrays
for(int i=0; i

More Related Content

Similar to Write a Java program that mimics the framework for an online movie i.pdf

do it in eclips and make sure it compile Goals1)Be able to.docx
do it in eclips and make sure it compile Goals1)Be able to.docxdo it in eclips and make sure it compile Goals1)Be able to.docx
do it in eclips and make sure it compile Goals1)Be able to.docx
jameywaughj
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
Jussi Pohjolainen
 
Objectives The main objective of this assignment is checking .docx
Objectives The main objective of this assignment is checking .docxObjectives The main objective of this assignment is checking .docx
Objectives The main objective of this assignment is checking .docx
amit657720
 
Objectives The main objective of this assignment is checking .docx
Objectives The main objective of this assignment is checking .docxObjectives The main objective of this assignment is checking .docx
Objectives The main objective of this assignment is checking .docx
vannagoforth
 
Windy City DB - Recommendation Engine with Neo4j
Windy City DB - Recommendation Engine with Neo4jWindy City DB - Recommendation Engine with Neo4j
Windy City DB - Recommendation Engine with Neo4j
Max De Marzi
 
Goals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docxGoals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docx
josephineboon366
 
Modify Assignment 5 toReplace the formatted output method (toStri.docx
Modify Assignment 5 toReplace the formatted output method (toStri.docxModify Assignment 5 toReplace the formatted output method (toStri.docx
Modify Assignment 5 toReplace the formatted output method (toStri.docx
adelaidefarmer322
 
Production.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdfProduction.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdf
sooryasalini
 

Similar to Write a Java program that mimics the framework for an online movie i.pdf (20)

Recommending Movies Using Neo4j
Recommending Movies Using Neo4j Recommending Movies Using Neo4j
Recommending Movies Using Neo4j
 
do it in eclips and make sure it compile Goals1)Be able to.docx
do it in eclips and make sure it compile Goals1)Be able to.docxdo it in eclips and make sure it compile Goals1)Be able to.docx
do it in eclips and make sure it compile Goals1)Be able to.docx
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder
 
Scmad Chapter07
Scmad Chapter07Scmad Chapter07
Scmad Chapter07
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Objectives The main objective of this assignment is checking .docx
Objectives The main objective of this assignment is checking .docxObjectives The main objective of this assignment is checking .docx
Objectives The main objective of this assignment is checking .docx
 
Objectives The main objective of this assignment is checking .docx
Objectives The main objective of this assignment is checking .docxObjectives The main objective of this assignment is checking .docx
Objectives The main objective of this assignment is checking .docx
 
Factorization Machines and Applications in Recommender Systems
Factorization Machines and Applications in Recommender SystemsFactorization Machines and Applications in Recommender Systems
Factorization Machines and Applications in Recommender Systems
 
Windy City DB - Recommendation Engine with Neo4j
Windy City DB - Recommendation Engine with Neo4jWindy City DB - Recommendation Engine with Neo4j
Windy City DB - Recommendation Engine with Neo4j
 
Goals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docxGoals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docx
 
Modify Assignment 5 toReplace the formatted output method (toStri.docx
Modify Assignment 5 toReplace the formatted output method (toStri.docxModify Assignment 5 toReplace the formatted output method (toStri.docx
Modify Assignment 5 toReplace the formatted output method (toStri.docx
 
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
Production.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdfProduction.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdf
 
Core java
Core javaCore java
Core java
 
Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#
 
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
 
The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30
 
public static void main(String[], args) throws FileNotFoundExcepti.pdf
public static void main(String[], args) throws FileNotFoundExcepti.pdfpublic static void main(String[], args) throws FileNotFoundExcepti.pdf
public static void main(String[], args) throws FileNotFoundExcepti.pdf
 

More from mohdjakirfb

Describe the stages of malaria and the site of protozoal activity on.pdf
Describe the stages of malaria and the site of protozoal activity on.pdfDescribe the stages of malaria and the site of protozoal activity on.pdf
Describe the stages of malaria and the site of protozoal activity on.pdf
mohdjakirfb
 
d. What types of information systems ru currently utilized at PVF Pr.pdf
d. What types of information systems ru currently utilized at PVF Pr.pdfd. What types of information systems ru currently utilized at PVF Pr.pdf
d. What types of information systems ru currently utilized at PVF Pr.pdf
mohdjakirfb
 
Bacteria growthExplain a growth curve.Explain lag phase, exponen.pdf
Bacteria growthExplain a growth curve.Explain lag phase, exponen.pdfBacteria growthExplain a growth curve.Explain lag phase, exponen.pdf
Bacteria growthExplain a growth curve.Explain lag phase, exponen.pdf
mohdjakirfb
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdf
mohdjakirfb
 
React to the following statement Knowledge is the technology wh.pdf
React to the following statement Knowledge is the technology wh.pdfReact to the following statement Knowledge is the technology wh.pdf
React to the following statement Knowledge is the technology wh.pdf
mohdjakirfb
 
please explain in detail What is the PCAOB Please explain what is t.pdf
please explain in detail What is the PCAOB Please explain what is t.pdfplease explain in detail What is the PCAOB Please explain what is t.pdf
please explain in detail What is the PCAOB Please explain what is t.pdf
mohdjakirfb
 

More from mohdjakirfb (20)

Describe the stages of malaria and the site of protozoal activity on.pdf
Describe the stages of malaria and the site of protozoal activity on.pdfDescribe the stages of malaria and the site of protozoal activity on.pdf
Describe the stages of malaria and the site of protozoal activity on.pdf
 
Database problem. Design a realtional schema based on E-R Diagram. B.pdf
Database problem. Design a realtional schema based on E-R Diagram. B.pdfDatabase problem. Design a realtional schema based on E-R Diagram. B.pdf
Database problem. Design a realtional schema based on E-R Diagram. B.pdf
 
d. What types of information systems ru currently utilized at PVF Pr.pdf
d. What types of information systems ru currently utilized at PVF Pr.pdfd. What types of information systems ru currently utilized at PVF Pr.pdf
d. What types of information systems ru currently utilized at PVF Pr.pdf
 
Bacteria growthExplain a growth curve.Explain lag phase, exponen.pdf
Bacteria growthExplain a growth curve.Explain lag phase, exponen.pdfBacteria growthExplain a growth curve.Explain lag phase, exponen.pdf
Bacteria growthExplain a growth curve.Explain lag phase, exponen.pdf
 
An ovum has all the nutrients stored that required for embryonic d.pdf
An ovum has all the nutrients stored that required for embryonic d.pdfAn ovum has all the nutrients stored that required for embryonic d.pdf
An ovum has all the nutrients stored that required for embryonic d.pdf
 
A plant with either the PP or Pp genotype has purple flowers, while .pdf
A plant with either the PP or Pp genotype has purple flowers, while .pdfA plant with either the PP or Pp genotype has purple flowers, while .pdf
A plant with either the PP or Pp genotype has purple flowers, while .pdf
 
________ ANOVA relies on matched samples in a similar way to the mat.pdf
________ ANOVA relies on matched samples in a similar way to the mat.pdf________ ANOVA relies on matched samples in a similar way to the mat.pdf
________ ANOVA relies on matched samples in a similar way to the mat.pdf
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdf
 
Which microtubule (MT) population binds to chromosomes during mitosi.pdf
Which microtubule (MT) population binds to chromosomes during mitosi.pdfWhich microtubule (MT) population binds to chromosomes during mitosi.pdf
Which microtubule (MT) population binds to chromosomes during mitosi.pdf
 
React to the following statement Knowledge is the technology wh.pdf
React to the following statement Knowledge is the technology wh.pdfReact to the following statement Knowledge is the technology wh.pdf
React to the following statement Knowledge is the technology wh.pdf
 
what animals first evolved true skeletonswhat animals first .pdf
what animals first evolved true skeletonswhat animals first .pdfwhat animals first evolved true skeletonswhat animals first .pdf
what animals first evolved true skeletonswhat animals first .pdf
 
true or false Different parts of the genome evolve at different spe.pdf
true or false Different parts of the genome evolve at different spe.pdftrue or false Different parts of the genome evolve at different spe.pdf
true or false Different parts of the genome evolve at different spe.pdf
 
The brightness in the center of a Fresnel diffraction pattern. Is al.pdf
The brightness in the center of a Fresnel diffraction pattern.  Is al.pdfThe brightness in the center of a Fresnel diffraction pattern.  Is al.pdf
The brightness in the center of a Fresnel diffraction pattern. Is al.pdf
 
Should Linda’s history of past improprieties lead Maria to withdraw .pdf
Should Linda’s history of past improprieties lead Maria to withdraw .pdfShould Linda’s history of past improprieties lead Maria to withdraw .pdf
Should Linda’s history of past improprieties lead Maria to withdraw .pdf
 
Problem 4.Organisms are present in ballast water discharged from a.pdf
Problem 4.Organisms are present in ballast water discharged from a.pdfProblem 4.Organisms are present in ballast water discharged from a.pdf
Problem 4.Organisms are present in ballast water discharged from a.pdf
 
Q2. Does Application Engine Generate SQLs like Query ManagerQ7. C.pdf
Q2. Does Application Engine Generate SQLs like Query ManagerQ7. C.pdfQ2. Does Application Engine Generate SQLs like Query ManagerQ7. C.pdf
Q2. Does Application Engine Generate SQLs like Query ManagerQ7. C.pdf
 
QUESTION 6- Delay spread of optical pulses results on multimode fibe.pdf
QUESTION 6- Delay spread of optical pulses results on multimode fibe.pdfQUESTION 6- Delay spread of optical pulses results on multimode fibe.pdf
QUESTION 6- Delay spread of optical pulses results on multimode fibe.pdf
 
31.A Biased sample is one that ______a. Is too smallb. Will al.pdf
31.A Biased sample is one that ______a. Is too smallb. Will al.pdf31.A Biased sample is one that ______a. Is too smallb. Will al.pdf
31.A Biased sample is one that ______a. Is too smallb. Will al.pdf
 
Please help me Im very confused thanks Find sin 2x, cos 2x, and tan .pdf
Please help me Im very confused thanks Find sin 2x, cos 2x, and tan .pdfPlease help me Im very confused thanks Find sin 2x, cos 2x, and tan .pdf
Please help me Im very confused thanks Find sin 2x, cos 2x, and tan .pdf
 
please explain in detail What is the PCAOB Please explain what is t.pdf
please explain in detail What is the PCAOB Please explain what is t.pdfplease explain in detail What is the PCAOB Please explain what is t.pdf
please explain in detail What is the PCAOB Please explain what is t.pdf
 

Recently uploaded

Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated crops
parmarsneha2
 

Recently uploaded (20)

Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated crops
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 

Write a Java program that mimics the framework for an online movie i.pdf

  • 1. Write a Java program that mimics the framework for an online movie information system similar to IMDB written in Java. Create an abstract base class, two subclasses, and one interface to provide basic functionality for the system. Use the provided UML, the class descriptions, and the test output to determine the proper behavior for your classes. Create an interface Rateable that: Provides a method vote(int numVotes, int voteScore). Create an abstract class Movie that: Implements the Rateable and Comparable interfaces. Provides the data fields: title, releaseYear, genre, numVotes, and voteScore. Provides four constructors: o Default, no-arg constructor o Three convenience constructors that allow as parameters: the title the title and releaseYear the title, releaseYear, and genre. Provides an abstract getInfo() method. Provides a concrete toString() method that returns the only movie title. Provides a concrete getRating() method that returns: o -1 if numVotes is 0, o voteScore/numVotes otherwise. Implements the Rateable interface’s vote() method by increasing the existing values of numVotes and voteScore by the amount passed in the appropriate parameter. Implements the Comparable interface’s compareTo() method by comparing ratings. Movies should be sorted in descending order, meaning that a higher rating should be considered “less than” a lower rating. Create a concrete class Horror that: Automatically sets the genre to Horror in its constructors. Adds a data attribute for number of deaths, numOfDeaths, with the appropriate getter/setter methods. 2 Provides a getInfo() method that returns “title, genre, releaseYear (rating): numDeaths deaths” with the appropriate values. o Detects if it receives a -1 from getRating() and uses “No ratings” as the rating. o To pass LiveLab’s auto-grader, make sure ratings are limited to one decimal place (see documentation on using String.format() which works similar to System.out.printf()). Create a concrete class Comedy that: Automatically sets the genre to Comedy in its constructors. Adds a data attribute, hasProfanity, to indicate whether there is profanity in the film with the appropriate getter/setter methods. Provides a getInfo() method that returns “title, genre, releaseYear (rating): Profanity/No Profanity” with the appropriate values. o Detects if it receives a -1 from getRating() and use “No ratings” as the rating. o To pass LiveLab’s auto- grader, make sure ratings are limited to one decimal place (see documentation on using
  • 2. String.format() which works similar to System.out.printf()). NOTE: Movie, Horror, and Comedy should provide all of the appropriate accessor/mutator methods for their data fields. For brevity, these are not included in the UML. Main method Create the horror movies: o A Nightmare on Elm Street, 1984, 4 deaths o Final Destination 5, 2011, 94 deaths1 o Saw, 2004, 6 deaths Create the comedy movies: o Napoleon Dynamite, 2004, no profanity o Keeping Up with the Joneses, 2016, profanity o Uncle Buck, 1989, profanity Use the vote() method to assign votes to the respective movies: (# votes - total vote score) o A Nightmare on Elm Street: 151,963 – 1,139,723 o Final Destination 5: 84,907 – 500,951 o Saw: 303,578 – 2,337,551 o Napoleon Dynamite: 163,240 – 1,126,356 o Uncle Buck: 64,031 – 448,217 Create an Array of type Movie and populate it with all of the created movies. Do not create them in sorted order, let the sort method handle that. Sort the array using the java.util.Arrays.sort() method. Using a loop, print the results of the getInfo() call for each movies in the sorted array. 1 http://finaldestination.wikia.com/wiki/List_of_deaths 3 Simplified UML Test Output Saw, Horror, 2004 (7.7): 6 deaths A Nightmare on Elm Street, Horror, 1984 (7.5): 4 deaths Napoleon Dynamite, Comedy, 2004 (6.9): No Profanity Uncle Buck, Comedy, 1989 (6.9): Profanity Final Destination 5, Horror, 2011 (5.9): 94 deaths Keeping Up with the Joneses, Comedy, 2016 (No ratings): Profanity Solution PROGRAM CODE: Rateable.java package movies; public interface Rateable {
  • 3. //abstract method for the rateable class public void vote(int numVotes, int voteScore); } Movie.java package movies; public abstract class Movie implements Rateable, Comparable{ // Data fields for the class String title; int releaseYear; String genre; int numVotes; int voteScore; // Default constructor Movie() { title = ""; genre = ""; } //Parameterized Constructors Movie(String title) { this.title = title; } Movie(String title, int releaseYear) { this.title = title; this.releaseYear = releaseYear; } Movie(String title, int releaseYear, String genre) { this.title = title; this.releaseYear = releaseYear; this.genre = genre;
  • 4. } //setters and getters public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public int getReleaseYear() { return releaseYear; } public void setReleaseYear(int releaseYear) { this.releaseYear = releaseYear; } public String getGenre() { return genre; } public void setGenre(String genre) { this.genre = genre; } public int getNumVotes() { return numVotes; } public void setNumVotes(int numVotes) { this.numVotes = numVotes; } public int getVoteScore() { return voteScore; } public void setVoteScore(int voteScore) { this.voteScore = voteScore; } // abstract method public abstract String getInfo();
  • 5. // toString() to return the movie title public String toString() { return this.title; } //getRating() method to calculate rating public int getRating() { if(this.numVotes > 0) return -1; else return this.voteScore/numVotes; } // method to define from Comparable interface @Override public int compareTo(Movie movie) { if(this.getRating() == movie.getRating()) return 0; else if(this.getRating() > movie.getRating()) return 1; else return -1; } //method to define from Rateable interface @Override public void vote(int numVotes, int voteScore) { this.numVotes = numVotes; this.voteScore = voteScore; } } Horror.java package movies;
  • 6. public class Horror extends Movie{ int numOfDeaths; String genre; //Setting the genre to Horror in default comstructor public Horror() { this.genre = "Horror"; } //setter and getter public int getNumOfDeaths() { return numOfDeaths; } public void setNumOfDeaths(int numOfDeaths) { this.numOfDeaths = numOfDeaths; } // Implementing the abstract method public String getInfo() { String rating = this.getRating() < 0? "No ratings": String.valueOf(this.getRating()); return this.title + "," + this.genre + "," + this.releaseYear + "(" + rating + "):" + this.numOfDeaths +"deaths"; } } Comedy.java package movies; public class Comedy extends Movie{ boolean hasProfanity; //Setters and getters public boolean isHasProfanity() { return hasProfanity;
  • 7. } public void setHasProfanity(boolean hasProfanity) { this.hasProfanity = hasProfanity; } public Comedy() { this.genre = "Comedy"; } @Override public String getInfo() { String rating = this.getRating() < 0? "No ratings": String.valueOf(this.getRating()); // using ternary operator to check if value is less than 0 String profanity = this.hasProfanity? "Profanity" : "No Profanity"; // using ternary operator to check if profanity is true or false and setting string value based on that return this.title + "," + this.genre + "," + this.releaseYear + "(" + rating + "):" + profanity; } } MainClass.java package movies; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import javax.sound.midi.ControllerEventListener; public class MainClass { public static void main(String[] args) { //creating objects for Horror and Comedy and adding data Horror horror = new Horror(); horror.setTitle("A Nightmare on Elm Street"); horror.setReleaseYear(1984); horror.setNumOfDeaths(4);
  • 8. Horror horror2 = new Horror(); horror2.setTitle("Final Destination 5"); horror2.setReleaseYear(2011); horror2.setNumOfDeaths(94); Horror horror3= new Horror(); horror3.setTitle("Saw"); horror3.setReleaseYear(2004); horror3.setNumOfDeaths(6); Comedy comedy1 = new Comedy(); comedy1.setTitle("Napolean Dynamite"); comedy1.setReleaseYear(2004); comedy1.setHasProfanity(false); Comedy comedy2 = new Comedy(); comedy2.setTitle("Keeping Up with the Joneses"); comedy2.setReleaseYear(2016); comedy2.setHasProfanity(true); Comedy comedy3 = new Comedy(); comedy3.setTitle("Uncle Buck"); comedy3.setReleaseYear(1989); comedy3.setHasProfanity(true); horror.vote(151963, 1139723); horror2.vote(84907, 500951); horror3.vote(303578, 2337551); comedy1.vote(163240, 1126356); comedy3.vote(64031, 448217); //creating an arraylist and adding all the movies into it ArrayList movieList = new ArrayList<>(); movieList.add(horror); movieList.add(horror2); movieList.add(horror3); movieList.add(comedy1);
  • 9. movieList.add(comedy2); movieList.add(comedy3); //creating an arraylist and adding all the movies into it Movie[] movies = new Movie[6]; movies[0] = horror; movies[1] = horror2; movies[2] = horror3; movies[3] = comedy1; movies[4] = comedy2; movies[5] = comedy3; //Sorting the arraylist Arrays.sort(movies); //printing the arrays for(int i=0; i