Consider a class Movie that contains information about a movie. The class has the following attributes:
Solution to Project 10
- The movie name
- The MPAA rating (e.g., G, PG, PG-13, R)
- The number of people who have rated this movie as a 1 (Terrible)
- The number of people who have rated this movie as a 2 (Bad)
- The number of people who have rated this movie as a 3 (OK)
- The number of people who have rated this movie as a 4 (Good)
- The number of people who have rated this movie as a 5 (Great)
Implement the class with accessors and mutators for the movie name and MPAA rating. Write a method addRating that takes an integer as an input parameter. The method should verify that the parameter is a number between 1 and 5, and if so, increment by one the number of people rating the movie that matches the input parameter. For example, if 3 is the input parameter, then the number of people who rated the movie as a 3 should be incremented by one. Write another method, getAverage, that returns the average value for all of the movie ratings. Test the class by writing a main method 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 5 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Concepts Of Programming Languages
Starting Out With Visual Basic (7th Edition)
Starting out with Visual C# (4th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
- Create a Right Triangle class that has two sides. Name your class rightTraingle. Code getter and setters for the base and the height. (Remember class variables are private.) The class should include a two-argument constructor that allows the program to set the base and height. The constructor should verify that all the dimensions are greater than 0. before assigning the values to the private data members. If a side is not greater than zero, set the value to -1. The class also should include two value-returning methods. One value-returning method should calculate the area of a triangle, and the other should calculate the perimeter of a triangle. If either side is -1, these functions return a -1. The formula for calculating the area of a triangle is 1/2 * b*h, where b is the base and h is the height. The formula for calculating the perimeter of a triangle is b+h+sqrt (b*b+h*h). Be sure to include a default constructor that initializes the variables of the base, height to -1. To test…arrow_forward1) Create a "Car" class that keeps car ids and prices. And create a "Galleries" class that holds the car list for a particular gallery. In this class there should be methods for get / set and print for car name, car number and car list. Adding / Removing Cars to the List in This Class should have methods. And create another method to find and print the IDs of Cars with Car Segment equal to X. (print (X)). Car Prices are as follows according to the segments. 0-19999 -> Z20000-29999 -> Y30000-44999 -> T45000-100000 -> P Apply the Car list using "Single Linked List"(Node, newNode, head). The program should be written in JAVA.arrow_forwardCreates a class Student with 3 attributes: name, id and level. a. Add a constructor able to create a Student; b. Add the methods getId and getLevel; c. Add the method display able to display the attributes,arrow_forward
- 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_forwardIn this activity, we are going to plan out and write a class definition that stores information for a book. Let's say we want to store the following information about this book: The book's name The book's author(s) (a book can have more than one author) The book's publisher The book's ISBN number The book's price The book's year of publication First, answer the following questions before the design: 1. What is a suitable name for this class? (Pick a name that best describes it).arrow_forwardWrite a shoe class with the following attributes: color (e.g., "blue", "green", "orange") displayName (e.g., "nikes, adidas", "puma") price (e.g., 100, 200,60) Include only one constructor. It should have parameters for each of the attributes and set their values. Additionally, include getters and setters for each of the attributes. Add a driver, name it Purchases, and create 2 objects. Finally, print out some information about both objects (i.e., print the information from some or all of the getters). For example, if you created a shoe object whose color was blue, whose display name was shoes , for a price of 230, you could use the getters to print something like this:These work trousers are blue and cost $230arrow_forward
- Create a class “Pizza”, and three sub-classes “Cheese Pizza”, “Pepperoni Pizza” and “VeggiePizza”. The class Pizza will have an attributes pizzaSize of type String and another attribute sizePrice of type double. The attribute sizePrice will give the price of the pizza sizes. The sizes can be small, medium and large and their respective price is Rs 600, Rs 800 and Rs 1000. Implement a method getSizePrice(String size) which returns the price of the size mentioned in parameter. Define a method calculatePrice(String size) which returns a double value. The three subclasses will have their attribute toppingPrice of type double. Create a test application where user should be able to: First select the appropriate Pizza type Then select the pizza size The system should then calculate total of price (This total should be total of the pizza size and topping) Display the complete order along with total price at the end Create all getter setters, use polymorphism and method overriding. Use your own…arrow_forwardCreate a class “Pizza”, and three sub-classes “Cheese Pizza”, “Pepperoni Pizza” and “VeggiePizza”. The class Pizza will have an attributes pizzaSize of type String and another attribute sizePrice of type double. The attribute sizePrice will give the price of the pizza sizes. The sizes can be small, medium and large and their respective price is Rs 600, Rs 800 and Rs 1000. Implement a method getSizePrice(String size) which returns the price of the size mentioned in parameter. Define a method calculatePrice(String size) which returns a double value. The three subclasses will have their attribute toppingPrice of type double. Create a test application where user should be able to: First select the appropriate Pizza type Then select the pizza size The system should then calculate total of price (This total should be total of the pizza size and topping) Display the complete order along with total price at the end Create all getter setters, use polymorphism and method overriding. Use your own…arrow_forwardThe goal of this coding exercise is to create two classes BookstoreBook and LibraryBook. Both classes have these attributes: author: Stringtiltle: Stringisbn : String- The BookstoreBook has an additional data member to store the price of the book, and whether the book is on sale or not. If a bookstore book is on sale, we need to add the reduction percentage (like 20% off...etc). For a LibraryBook, we add the call number (that tells you where the book is in the library) as a string. The call number is automatically generated by the following procedure:The call number is a string with the format xx.yyy.c, where xx is the floor number that is randomly assigned (our library has 99 floors), yyy are the first three letters of the author’s name (we assume that all names are at least three letters long), and c is the last character of the isbn.- In each of the classes, add the setters, the getters, at least three constructors (of your choosing) and override the toString method (see samplerun…arrow_forward
- Create and build a collection of classes that define various forms of reading material, including as books, novels, periodicals, technical journals, and textbooks. Include data values that characterise the material's different qualities, such as the number of pages and the names of the main characters. Include methods for each class that are suitably titled and print an acceptable message. Create a driver class that will be used to instantiate and test various of the classes.arrow_forwardFinish the TestPlane class that contains a main method that instantiates at least two Planes. Add instructions to instantiate your favorite plane and invoke each of the methods with a variety of parameter values to test each option within each method. To be able to test the functionality of each phase, you will add instructions to the main method in each phase.arrow_forwardA. Create a BankAccount class. We want to be able to create a new bank account, make deposits and withdrawals, and check the balance. Each bank account created should receive a unique account id, numbered sequentially 1001, 1002, 1003, and so on. We should be able to change the name on the account. We should also be able to retrieve the account id and the name on the account. Provide a constructor that takes a name for the account as a parameter. Remember that a constructor has the same name as the class. The constructor should initialize all of the instance variables. What does the class need to remember? Those are the instance variables. There should be three. Provide the following methods: public double getID() gets the account id of this BankAccount public double getBalance() gets the balance of this BankAccount public String getName() gets the name of this BankAccount public void setName(String newName) sets a new name for this BankAccount public void deposit(double…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education