HW 4 Code (In Java) import java.util.Scanner; class Movie { private String name; private String mipaaRating; private int terrible; private int bad; private int ok; private int good; private int great; public Movie(String name, String mipaaRating) { this.name = name; this.mipaaRating = mipaaRating; this.terrible = 0; this.bad = 0; this.ok = 0; this.good = 0; this.great = 0; } //Adding the ratings for Terrible to Excellent rating public void addRating(int rating) { if (rating >= 1 && rating <= 5) { switch (rating) { case 1: this.terrible++; break; case 2: this.bad++; break; case 3: this.ok++; break; case 4: this.good++; break; case 5: this.great++; break; } } } // Finds the average for every single rating when given public double getAverage() { int total = this.terrible + this.bad + this.ok + this.good + this.great; if (total == 0) { return 0; } else { double sum = this.terrible + (2 * this.bad) + (3 * this.ok) + (4 * this.good) + (5 * this.great); double avg = sum / total; return Math.round(avg * 100.0) / 100.0; } } public String getName() { return this.name; } public String getMipaaRating() { return this.mipaaRating; } // Prints out the # of ratings public void printRatings() { System.out.println("Number of people rating the movie as 1 (Terrible): " + this.terrible); System.out.println("Number of people rating the movie as 2 (Bad): " + this.bad); System.out.println("Number of people rating the movie as 3 (OK): " + this.ok); System.out.println("Number of people rating the movie as 4 (Good): " + this.good); System.out.println("Number of people rating the movie as 5 (Great): " + this.great); } } //Main code for the processing of the coding public class TestMovieRating { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the name of the movie: "); String name = scanner.nextLine(); System.out.print("Enter the MIPAA rating of the movie: "); String mipaaRating = scanner.nextLine(); Movie movie = new Movie(name, mipaaRating); //For implementing the ratings int rating = 0; while (rating != -1) { System.out.print("Enter a rating between 1 and 5 (-1 to stop): "); rating = scanner.nextInt(); //When to stop the rating if all are the ratings are filled in if (rating == -1) { break; } else { movie.addRating(rating); } } System.out.println("Name: " + movie.getName()); System.out.println("MIPAA rating: " + movie.getMipaaRating()); movie.printRatings(); System.out.println("Average rating: " + movie.getAverage()); } }
HW 4 Code (In Java) import java.util.Scanner; class Movie { private String name; private String mipaaRating; private int terrible; private int bad; private int ok; private int good; private int great; public Movie(String name, String mipaaRating) { this.name = name; this.mipaaRating = mipaaRating; this.terrible = 0; this.bad = 0; this.ok = 0; this.good = 0; this.great = 0; } //Adding the ratings for Terrible to Excellent rating public void addRating(int rating) { if (rating >= 1 && rating <= 5) { switch (rating) { case 1: this.terrible++; break; case 2: this.bad++; break; case 3: this.ok++; break; case 4: this.good++; break; case 5: this.great++; break; } } } // Finds the average for every single rating when given public double getAverage() { int total = this.terrible + this.bad + this.ok + this.good + this.great; if (total == 0) { return 0; } else { double sum = this.terrible + (2 * this.bad) + (3 * this.ok) + (4 * this.good) + (5 * this.great); double avg = sum / total; return Math.round(avg * 100.0) / 100.0; } } public String getName() { return this.name; } public String getMipaaRating() { return this.mipaaRating; } // Prints out the # of ratings public void printRatings() { System.out.println("Number of people rating the movie as 1 (Terrible): " + this.terrible); System.out.println("Number of people rating the movie as 2 (Bad): " + this.bad); System.out.println("Number of people rating the movie as 3 (OK): " + this.ok); System.out.println("Number of people rating the movie as 4 (Good): " + this.good); System.out.println("Number of people rating the movie as 5 (Great): " + this.great); } } //Main code for the processing of the coding public class TestMovieRating { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the name of the movie: "); String name = scanner.nextLine(); System.out.print("Enter the MIPAA rating of the movie: "); String mipaaRating = scanner.nextLine(); Movie movie = new Movie(name, mipaaRating); //For implementing the ratings int rating = 0; while (rating != -1) { System.out.print("Enter a rating between 1 and 5 (-1 to stop): "); rating = scanner.nextInt(); //When to stop the rating if all are the ratings are filled in if (rating == -1) { break; } else { movie.addRating(rating); } } System.out.println("Name: " + movie.getName()); System.out.println("MIPAA rating: " + movie.getMipaaRating()); movie.printRatings(); System.out.println("Average rating: " + movie.getAverage()); } }
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
HW 4 Code (In Java)
import java.util.Scanner;
class Movie {
private String name;
private String mipaaRating;
private int terrible;
private int bad;
private int ok;
private int good;
private int great;
public Movie(String name, String mipaaRating) {
this.name = name;
this.mipaaRating = mipaaRating;
this.terrible = 0;
this.bad = 0;
this.ok = 0;
this.good = 0;
this.great = 0;
}
//Adding the ratings for Terrible to Excellent rating
public void addRating(int rating) {
if (rating >= 1 && rating <= 5) {
switch (rating) {
case 1:
this.terrible++;
break;
case 2:
this.bad++;
break;
case 3:
this.ok++;
break;
case 4:
this.good++;
break;
case 5:
this.great++;
break;
}
}
}
// Finds the average for every single rating when given
public double getAverage() {
int total = this.terrible + this.bad + this.ok + this.good + this.great;
if (total == 0) {
return 0;
} else {
double sum = this.terrible + (2 * this.bad) + (3 * this.ok) + (4 * this.good) + (5 * this.great);
double avg = sum / total;
return Math.round(avg * 100.0) / 100.0;
}
}
public String getName() {
return this.name;
}
public String getMipaaRating() {
return this.mipaaRating;
}
// Prints out the # of ratings
public void printRatings() {
System.out.println("Number of people rating the movie as 1 (Terrible): " + this.terrible);
System.out.println("Number of people rating the movie as 2 (Bad): " + this.bad);
System.out.println("Number of people rating the movie as 3 (OK): " + this.ok);
System.out.println("Number of people rating the movie as 4 (Good): " + this.good);
System.out.println("Number of people rating the movie as 5 (Great): " + this.great);
}
}
//Main code for the processing of the coding
public class TestMovieRating {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the name of the movie: ");
String name = scanner.nextLine();
System.out.print("Enter the MIPAA rating of the movie: ");
String mipaaRating = scanner.nextLine();
Movie movie = new Movie(name, mipaaRating);
//For implementing the ratings
int rating = 0;
while (rating != -1) {
System.out.print("Enter a rating between 1 and 5 (-1 to stop): ");
rating = scanner.nextInt();
//When to stop the rating if all are the ratings are filled in
if (rating == -1) {
break;
} else {
movie.addRating(rating);
}
}
System.out.println("Name: " + movie.getName());
System.out.println("MIPAA rating: " + movie.getMipaaRating());
movie.printRatings();
System.out.println("Average rating: " + movie.getAverage());
}
}
class Movie {
private String name;
private String mipaaRating;
private int terrible;
private int bad;
private int ok;
private int good;
private int great;
public Movie(String name, String mipaaRating) {
this.name = name;
this.mipaaRating = mipaaRating;
this.terrible = 0;
this.bad = 0;
this.ok = 0;
this.good = 0;
this.great = 0;
}
//Adding the ratings for Terrible to Excellent rating
public void addRating(int rating) {
if (rating >= 1 && rating <= 5) {
switch (rating) {
case 1:
this.terrible++;
break;
case 2:
this.bad++;
break;
case 3:
this.ok++;
break;
case 4:
this.good++;
break;
case 5:
this.great++;
break;
}
}
}
// Finds the average for every single rating when given
public double getAverage() {
int total = this.terrible + this.bad + this.ok + this.good + this.great;
if (total == 0) {
return 0;
} else {
double sum = this.terrible + (2 * this.bad) + (3 * this.ok) + (4 * this.good) + (5 * this.great);
double avg = sum / total;
return Math.round(avg * 100.0) / 100.0;
}
}
public String getName() {
return this.name;
}
public String getMipaaRating() {
return this.mipaaRating;
}
// Prints out the # of ratings
public void printRatings() {
System.out.println("Number of people rating the movie as 1 (Terrible): " + this.terrible);
System.out.println("Number of people rating the movie as 2 (Bad): " + this.bad);
System.out.println("Number of people rating the movie as 3 (OK): " + this.ok);
System.out.println("Number of people rating the movie as 4 (Good): " + this.good);
System.out.println("Number of people rating the movie as 5 (Great): " + this.great);
}
}
//Main code for the processing of the coding
public class TestMovieRating {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the name of the movie: ");
String name = scanner.nextLine();
System.out.print("Enter the MIPAA rating of the movie: ");
String mipaaRating = scanner.nextLine();
Movie movie = new Movie(name, mipaaRating);
//For implementing the ratings
int rating = 0;
while (rating != -1) {
System.out.print("Enter a rating between 1 and 5 (-1 to stop): ");
rating = scanner.nextInt();
//When to stop the rating if all are the ratings are filled in
if (rating == -1) {
break;
} else {
movie.addRating(rating);
}
}
System.out.println("Name: " + movie.getName());
System.out.println("MIPAA rating: " + movie.getMipaaRating());
movie.printRatings();
System.out.println("Average rating: " + movie.getAverage());
}
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education