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++ (9th 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)
- Implement 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_forwardIn 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_forward
- The Robot class models the state and behavior of virtual robots. Each robot corresponds to an object that is an instance of this class. Each robot: properties: Has a modelNumber (int) Has a direction(String): given by the direction attribute that takes one of the values "North", "East", "South" or "West" Has a makeYear (int): the year the robot was made. Methods: Can turn left 90 ° to change direction (if its direction was "North" it becomes "West", if it was "West" it becomes "South", if it was "South" it becomes "North", etc.). with the method without parameter turnLeft () Can display its detail with the method myInfo().arrow_forwardHelp, I making a elevator simulator. I have to use polymorphism and object oriented programming to write this code. Can someone please help me improve this code I have. The remaining code is in the pictures. Any help is appreciated. Thank You! The simulation should have 4 types of Passengers: Standard: This is the most common type of passenger and has a request percentage of 70%. Standard passengers have no special requirements. VIP: This type of passenger has a request percentage of 10%. VIP passengers are given priority and are more likely to be picked up by express elevators. Freight: This type of passenger has a request percentage of 15%. Freight passengers have large items that need to be transported and are more likely to be picked up by freight elevators. Glass: This type of passenger has a request percentage of 5%. Glass passengers have fragile items that need to be transported and are more likely to be picked up by glass elevators. The simulation should also have 4 types…arrow_forwardStatic members of a class are... When and how can you take advantage of these opportunities?arrow_forward
- Consider 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_forwardProgram 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_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_forwardjust mention the Anwsers. Explanation is not needed. Thank youarrow_forwardCreate an Employee Class that will have Two instance variable: name and workingPeriod A class method named employeeByJoiningYear(): • To create an Employee object by joining year for calculating the working period o it will have two Parameter name and year • A static method experienceCheck() to check if an Employee is experienced or not o It will take working period and gender as parameter o If an employee's working period is less than 3, he or she is not experienced [You are not allowed to change the code below] # Write your code here employee1 = Employee('Dororo', 3) employee2 = Employee.employeeByJoiningYear('Harry', 2016) 6 print(employee1.workingPeriod) print(employee2.workingPeriod) print(employee1.name) print(employee2.name) print(Employee.experienceCheck(2, "male")) print(Employee.experienceCheck(3, "female")) Оutput 3 Dororo Harry He is not experienced She is experiencedarrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT