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 (8th 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 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
- Part I Create a Ticket class. The design is up to you. Write the necessary methods. Part II Create a MovieTicket class that inherits from Ticket class. The design is up to you. Write the necessary methods. Part III Create a Theater class. The design is up to you. Write the necessary methods.arrow_forwardCreate 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_forwardConsider a class ScienceFairProjectRating that will be used to help judge a science fair project. The attributes for the new class are The name of the project A unique identification string for the project The name of the person A rating for the creative ability (max. 30) A rating for the scientific thought (max. 30) A rating for thoroughness (max. 15) A rating for technical skills (max. 15) A rating for clarity (max. 10) It will have methods to Get the number of judges Get all the ratings for a particular project Return the total of the ratings for a particular project Return the maximum total rating possible Return a string showing a project’s rating in a format suitable for display Write a method heading for each method. Write preconditions and postconditions for each method. Write some Java statements that test the class. Implement the class.arrow_forward
- A. 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_forwardDirectionsThe total cost of a group of items at a grocery store is based on the sum of the individual product prices and the tax (which is 5.75%). Products that are considered “necessities” are not taxed, whereas products that are considered “luxuries” are. For this practice problem you will need to download Shopping Trip Starting Code.zip The Product class is abstract, and it has a method called getTotalPrice. Your task is to create two subclasses of Product: NecessaryProduct and LuxuryProduct and implement the getTotalPrice method in each of these classes appropriately.Then modify the driver program to instantiate four products (two necessary and two luxury) and store them in the product array, print out each item in the array, and display the total cost of the items. You should not make any change at all to Product.java, and you should only add to ShoppingTripStartingCode.java. Do not change any code that is already present. Make sure that it is for anygiven…arrow_forwardTask Write a class named Account to represent an account that you may find at a bank. Accounts have a balance and an annual interest rate. Include attributes in the Account class to reflect these. Write getters for both attributes and a setter for only the annual interest rate. Think about how real bank accounts work, you change your balance by withdrawing and depositing money, not just by telling the banker how much you want to change it to. Include a constructor with parameters used to assign values to both attributes. Users should be able to withdraw money from an Account, deposit money into an Account, find monthly interest rate, and find monthy interest. Include methods for each of these actions. More details on them below. withdraw method This method simulates withdrawing money from the Account. It should not return a value and take the amount to withdraw as a parameter and reduce the balance by this amount. deposit method This method simulates depositing money into the Account.…arrow_forward
- Animals need energy to move. They get energy from eating food while moving consumes energy. Create a class Animal with a constructor that takes no parameters and has an instance variable: private int energy; When an animal is "born," it has one unit of energy. It has the methods public void eat(int amountToEat) - which increases the amount of energy the animal has by amountToEat public void move(int amountToMove) - which decreases the energy the animal has by amountToMove. public int getEnergy() - which returns the amount of energy left Notice there is no setEnergy method. Energy is only changed by eating or moving. Since it isn't realistic for animals to be able to gather infinite amounts of energy, to have negative energy or to eat or move a negative amount, you should create a subclass BetterAnimal which has a cap on the amount of energy an animal can have. The constructor takes a parameter that specifies a maximum for energy. You will need to save this in another instance…arrow_forwardAnimals need energy to move. They get energy from eating food while moving consumes energy. Create a class Animal with a constructor that takes no parameters and has an instance variable: private int energy; When an animal is "born," it has one unit of energy. It has the methods public void eat(int amountToEat) - which increases the amount of energy the animal has by amountToEat public void move(int amountToMove) - which decreases the energy the animal has by amountToMove. public int getEnergy() - which returns the amount of energy left Notice there is no setEnergy method. Energy is only changed by eating or moving. Since it isn't realistic for animals to be able to gather infinite amounts of energy, to have negative energy or to eat or move a negative amount, you should create a subclass BetterAnimal which has a cap on the amount of energy an animal can have. The constructor takes a parameter that specifies a maximum for energy. You will need to save this in another instance…arrow_forwardConsider the class Movie that contains information about a movie. The class has the following attributes: . The movie name • The SA Film and Publication Board (FPB) rating (for example, A, PG, 7-9 PG, 10-12 PG, 13, 16, 18, X18, XX) 1 • The number of people that have rated this movie as 1 (Terrible) • The number of people that have rated this movie as 2 (Bad) • The • The • The number of people that have rated this movie as 3 (OK) number of number of people that have rated this movie as 4 (Good) people that have rated this movie as 5 (Great) The class Movie you created, can be implemented more efficiently if we use an array instead of 5 different member variables to count the number of people rating a movie at a specific score. Adjust your class Movie to use an array to count the score ratings for a movie, and test it with the same main function.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