Consider a class Movie that contains information about a movie. The class has the following attributes:
■ The movie name
■ The MPAA rating (for example, G, PG, PG-13, R)
■ The number of people that have rated this movie as a 1 (Terrible)
■ The number of people that have rated this movie as a 2 (Bad)
■ The number of people that have rated this movie as a 3 (OK)
■ The number of people that have rated this movie as a 4 (Good)
■ The number of people that have rated this movie as a 5 (Great)
Implement the class with accessor and mutator functions for the movie name and MPAA rating. Write a function addRating that takes an integer as an input parameter. The function should verify that the parameter is a number between 1 and 5, and if so, increment the number of people rating the movie that match the input parameter. For example, if 3 is the input parameter, then the number of people that rated the movie as a 3 should be incremented by 1. Write another function, getAverage, that returns the average value for all of the movie ratings. Finally, add a constructor that allows the programmer to create the object with a specified name and MPAA rating. The number of people rating the movie should be set to 0 in the constructor.
Test the class by writing a main function that creates at least two movie objects, adds at least five ratings for each movie, and outputs the movie name, MPAA rating, and average rating for each movie object.
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Digital Fundamentals (11th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Artificial Intelligence: A Modern Approach
Starting Out with C++ from Control Structures to Objects (9th Edition)
- Create a class Person to represent a person according to the following requirements: A person has two attributes: id Add a constructer to initialize all the attributes to specific values. Add all setter and getter methods. Create a class Product to represent a product according to the following requirements: A product has four attributes: a reference number (can’t be changed) a price an owner (is a person) a shopName (is the same for all the products). Add a constructer without parameters to initialize all the attributes to default values (0 for numbers, "" for a string and null for object). Add a second constructer to initialize all the attributes to specific values. Use the keyword "this". Add the method changePrice that change the price of a product. The method must display an error message if the given price is negative. Add a static method changeShopName to change the shop name. Add all the getter methods. The method getOwner must return an owner. Create the class…arrow_forwardImplement the following class Employee. This class is composed by 4 attributes and 3 methods. 1) Create a class Employee containing: _init_( ) method to initialize the different attributes . Get EmployeeName method Get EmployeeSSN method . Get EmployeeDepartment method 2) Define the method main to create 4 employees and apply the different methods Employee # Name: # Social Security Number: # Department # Salary + + Get Employee Name() Get Employee Social Security Number() + Get Employee Department() 3arrow_forwardIn a university there are different classrooms, offices and departments. A department has a name and it contains many offices. A person working at the university has a unique ID and can be a professor or an employee. "A professor can be a full, associate or assistant professor and he/she is enrolled in one department. •Offices and classrooms have a number ID, and a classroom has a number of seats. • Every employee works in an office. 1. Draw the class diagram for the scenario abovearrow_forward
- In this lesson, we are going to create an Assignment superclass with a Test and Project subclass. Assignment class The Assignment class should have the following three instance variables: String name double availablePoints double earnedPoints The constructor heading should be: public Assignment(String name, double availablePoints, double earnedPoints) Test class The Test class should have the following instance variable: String testDate The constructor heading should be: public Test(String name, double availablePoints, double earnedPoints, String testDate) Project class The Project class should have the following instance variables: String dueDate boolean groups The constructor heading should be: public Project(String name, double availablePoints, double earnedPoints, String dueDate, boolean groups) Each class should have getters and setters for each of its instance variables. AssignmentRunner class The AssignmentRunner should loop and prompt users for an assignment name until…arrow_forwardBased on this Class diagram, create a Package diagram for an online grocery shopping system.arrow_forwardConsider a class MotorBoat that represents motorboats. A motorboat has attributes for The capacity of the fuel tank The amount of fuel in the tank The maximum speed of the boat The current speed of the boat The efficiency of the boat’s motor The distance traveled The class has methods to Change the speed of the boat Operate the boat for an amount of time at the current speed Refuel the boat with some amount of fuel Return the amount of fuel in the tank Return the distance traveled so far If the boat has efficiency e, the amount of fuel used when traveling at a speed s for time t is . The distance traveled in that time is . Note: distance = time * speed, fuel used = distance /efficiency. Write a method heading for each method. Write preconditions and post conditions for each method. Write some Java statements that test the class. Implement the class.arrow_forward
- Program thisarrow_forwardThe Point2D should store an x and y coordinate pair, and will be used to build a new class via class composition. A Point2D has a x and a y, while a LineSegment has a start point and an end point (both of which are represented as Point2Ds). class Invariants The start and end points of a line segment should never be null Initialize these to the origin instead. Data A LineSegment has a start point This is a Point2D object All data will be private A LineSegment also has an end point. Also a Point2D object Methods Create getters and setters for your start and end points public Point2D getStartPoint() { public void setStartPoint(Point2D start) { Create a toString() function to build a string composed of the startPoint’s toString() and endPoint’s toString() Should look like “Line start(0,0) and end(1,1)” Create an equals method that determines if two LineSegments are equal public boolean equals(Object other) { if(other == null || !(other instanceof LineSegment)) return…arrow_forwardShow Rehearse Click to add notes Set Up Hide Side Show Side ● Record Timings Side Show ✅Show Media Controls Task 1 Create a package called Adoption Center with the two classes Petinfo.java and PetOwnerInfo.java Petinfo: Create a class called PetInfo.java that has the following: name, age, weight, type as private attributes, a parameterized constructer that sets all the attributes, a getter for name, a setter for age, and a display() method that prints in the following format Milo is a dog who is 4 years old and weighs 10.5 lbs. PetOwnerinfo: Create a class called PetOwnerinfo.java that has the following: name, email, and age as private attributes, a parametrized constructor that sets all the attributes, a getter for name, a setter methods for email, and a display() method that prints in the following format Skippy is 28 years old. Their email is iLoveMilo@gmail.com. Add JavaDoc comments to both classesarrow_forward
- Q# A program that has no graphical user interface and only takes input through the command line only has a model and a controller. It does not have a view. The answer: is FALSE. Please explain with example. Q# What is NOT an effect of the SOLID principles? The answer: A high-level class depends on specific low-level classes and not interfaces. Please explain why. Q# Assume you are considering writing a method and are deciding what should happen when given input that is outside of perfect input. Which of the following is not a way to handle this? Answer: Use better JUnit testing. Subject: Java Programmingarrow_forwardComputer Science Create UML Class Diagrams for the 2 following java classes which will be used in a connect X game. GameScreen.javaThis will be the class that contains the main() method and controls the game's flow. It willalternate the game between players, say whose turn it is, get the column they would like, and placetheir marker. If the player chooses a location that is not available (either because the column is full orbecause it is outside the bounds of the 6 x 9 board), then the program will print a message saying thespace is unavailable and ask them to enter a new column. Once a placement has been made, it willcheck to see if either player has won. If so, it will print off a congratulatory message, and ask if theywould like to play again and prompt them for a response of "Y" or "N". If they choose to play again, itshould present them with a blank board and start the game over. If a player has not won, it will check tosee if the game has ended in a tie (no spaces left on the…arrow_forwardjust mention the Anwsers. Explanation is not needed. Thank youarrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT