Implement a class name move that information about a movie T

Implement a class name move that information about a movie. The Movie class has the following instance variables (a.k.a. fields or data): The movie name The director\'s name The MPAA rating (e.g. G, PG, PG-13, R) Number of people who have rated movie as terrible (1) Number of people who have rated movie as bad (2) Number of people who have rated movie as ok (3) Number of people who have rated movie as good (4) Number of people who have rated movie as excellent (5) The Movie class will have methods to: Create a new Movie (given a movie name, director name and MPAA rating) [constructor] Create a new Movie (from another Movie) [copy constructor] *** Add accessors/mutators for: movie name, director name, MPAA rating*** Add only accessors for: getTerribleNumber - returns the number of people who rated movie as terrible getBadNumber getOkNumber getGoodNumber getExcellentNumber calculateAverageRating - calculAtes and returns the average rating by multiplying the number of terrible ratings * 1, bad ratings * 2, ok ratings * 3, good ratings * 4, excellent ratings * 5 and dividing by the total number of ratings. If there are no ratings for the movie yet, return 0.0 addRating(int rating) - adds a rating for the movie, returns true if rating is between 1-5, false otherwise. removeRating(int rating) - removes a rating for a movie. Returns true if rating is between 1-5 and there is at least one rating to remove, false otherwise equals - method to check if one Movie is the same as another by comparing ail instance variables toString - method to turn a Movie into a string for display, e.g. display as \"Movie [Name=Orange County, Director=Jake Kasdan, MPAA Rating=PG- 13, Average Rating=2.5]\" Below is a class diagram to assist with the requirements of the Movie class:

Solution

movie.java :

import java.util.Objects;

public class movie {
private String mname;
private String dname;
private String rating;
private int terrible;
private int bad;
private int ok;
private int good;
private int excellent;
int avg;

public movie(String mname, String dname, String rating) {
this.mname = mname;
this.dname = dname;
this.rating = rating;
}
public String getMname() {
return mname;
}
public void setMname(String mname) {
this.mname = mname;
}
public String getDname() {
return dname;
}
public void setDname(String dname) {
this.dname = dname;
}
public String getRating() {
return rating;
}
public void setRating(String rating) {
this.rating = rating;
}
public int getTerrible() {
return terrible;
}
public int getBad() {
return bad;
}
public int getOk() {
return ok;
}
public int getGood() {
return good;
}
public int getExcellent() {
return excellent;
}
public int calculateAverageRating()
{
if(terrible==0 && bad==0 && ok==0 && good==0 && excellent==0)
return avg;
else
{
avg = (terrible*1 + bad*2 + ok*3 + good*4 + excellent*5)/(terrible + bad + ok + good + excellent);
}
return avg;
}
  
boolean addRating(int rating)
{
if(rating<1 || rating>5)
return false;
else if(rating==1)
this.terrible = this.terrible + 1;
else if(rating==2)
this.bad = this.bad + 1;
else if(rating==3)
this.ok = this.ok + 1;
else if(rating==4)
this.good = this.good + 1;
else if(rating==5)
this.excellent = this.excellent + 1;
return true;
}
  
boolean removeRating(int rating)
{
if(rating<1 || rating>5)
return false;
else if(rating==1)
this.terrible = this.terrible - 1;
else if(rating==2)
this.bad = this.bad - 1;
else if(rating==3)
this.ok = this.ok - 1;
else if(rating==4)
this.good = this.good - 1;
else if(rating==5)
this.excellent = this.excellent - 1;
return true;
}
  
@Override
public String toString() {
return \"Movie{{\" + \"Name=\" + mname + \", Director=\" + dname + \", MPAA rating=\" + rating + \", Average Rating=\" + avg + \'}\';
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final movie other = (movie) obj;
if (!Objects.equals(this.mname, other.mname)) {
return false;
}
if (!Objects.equals(this.dname, other.dname)) {
return false;
}
if (!Objects.equals(this.rating, other.rating)) {
return false;
}
if (this.terrible != other.terrible) {
return false;
}
if (this.bad != other.bad) {
return false;
}
if (this.ok != other.ok) {
return false;
}
if (this.good != other.good) {
return false;
}
if (this.excellent != other.excellent) {
return false;
}
return true;
}
  
  
}

movieDemo.java :

public class movieDemo {
public static void main(String a[]){
movie m = new movie(\"despicable me\",\"Coffin\",\"G\");
m.addRating(4);
m.addRating(5);
System.out.println(\"Average : \"+m.calculateAverageRating());
m.removeRating(4);
System.out.println(\"Average : \"+m.calculateAverageRating());
  
  
}
}

Output:
run:
Average : 4
Average : 5
BUILD SUCCESSFUL (total time: 41 seconds)

 Implement a class name move that information about a movie. The Movie class has the following instance variables (a.k.a. fields or data): The movie name The di
 Implement a class name move that information about a movie. The Movie class has the following instance variables (a.k.a. fields or data): The movie name The di
 Implement a class name move that information about a movie. The Movie class has the following instance variables (a.k.a. fields or data): The movie name The di

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site