Explanation of Solution
a.
Method heading for each method:
- • Method heading for read rating from user is “public void readRating()”.
- • Method heading for gets maximum rating is “public int getMaximumRating()”...
Explanation of Solution
b.
Preconditions and postconditions of each method:
- • Precondition and postcondition of “public void readRating()” method.
- ○ Precondition: Display maximum rating range for given description using object of “RatingScore” class.
- ○ Postcondition: The “the_rating” is assigned to “value”.
- • Precondition and postcondition of “getMaximumRating()” method.
- ○ Precondition: None...
Explanation of Solution
c.
Test class for some Java statement:
//Create object "movieScore" from "RatingScore" class
RatingScore movieScore = new RatingScore();
//Create object "restaurantScore" from "RatingScore" class
RatingScore restaurantScore = new RatingScore();
//Call "setRatingScore" method for object "movieScore"
movieScore.setRatingScore("Merry's excellent movie", 8);
//Call "setRatingScore" method for object "restaurantScore"
restaurantScore.setRatingScore("Food quality", 20);
//Read rating for object "movieScore" by calling the method "readRating".
movieScore.readRating();
//Display the given statement
System...
Explanation of Solution
d.
Implementation of class:
RatingScore.java:
//Import package
import java.util.Scanner;
//Define a class "RatingScore"
public class RatingScore
{
//Declare required instance variable
private String desc;
private int maximum_rating;
private int the_rating;
//Set values to "RatingScore" attributes
public void setRatingScore(String d, int m)
{
desc = d;
maximum_rating = m;
the_rating = -1;
}
//Method definition for read rating from user
public void readRating()
{
//Display given statement for description
System.out.println("Enter rating for " + desc + ":");
//Display given maximum rating
System.out.println("Please enter an integer from 0 to " + maximum_rating);
//Create object for Scanner class
Scanner r = new Scanner(System.in);
//Assign "value" to "-1"
int value = -1;
//Assign required rating to "true"
boolean requiredRating = true;
//Check rating condition using "while" loop
while(requiredRating)
{
//Read input from user
value = r.nextInt();
if(value >= 0 && value <= maximum_rating)
{
requiredRating = false;
}
else
{
System.out.println("Error: The given rating is out of range.");
System.out.println("Enter an integer from 0 to " + maximum_rating);
}
}
the_rating = value;
}
//Method definition for gets maximum rating
public int getMaximumRating()
{
//Returns maximum rating
return maximum_rating;
}
//Method definition for gets rating
public int getRatingValue()
{
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
- Write a java program that models a restaurant ordering system. You will need to have the following methods: public static int displayMenu() This method will display the menu items and price per item. Please keep the same 5 items as I have. You need an option so that the customer can indicate that ordering is done. This method will read the choice from the customer and return that number. public static double getQuantityAndCost(int x) This method will prompt the user for the quantity for the menu choice and then multiply by the appropriate amount. For example, if the user had selected Tacos, then x would be passed in as the value 2 and the return value for this method would be 2 * 4.00. public static double AddTipAmount(double sum) This method will prompt the user for a tip amount. The method receives sum which is the total on the bill after the user has selected Done ordering. For example, the method is called with a sum of 22.00 and the user indicate 10 percent for the tip, the…arrow_forwardQuestionarrow_forwardQuestionarrow_forward
- In java Write a program on value passing from one method to another and also write separate program for 1. Value passing from one class to another 2. Multiple value passing from one method to anotherarrow_forwardJAVA - Please produce both a product.java file and a productprinter.java file (tester) Implement a class Product. A product has a name and a price, for example new Product("Toaster", 29.95). Supply methods getName, getPrice, and reducePrice. Supply a program ProductPrinter that makes two products, prints each name and price, reduces their prices by $5.00, and then prints the prices again.arrow_forwardTask 1: Write a Java Program which will determine whether a number is even or odd. Take the number as an input from the user. Perform the checking in a separate method other than main method. Print the results in main method. Task 2: Find out the area of three geometric shape: Circle, Triangle, Square. Give the user an option to select which geometric shape's area he/she wants to find out. Based on the choice take necessary input and find out the result. Use different area method for each geometric shape. Print the result in main method.arrow_forward
- Write a java program that prints student’s name, grades and GPA. You must do the following requirements: Create three methods: First method to accept and print your first, last name, and GPA. Second method to accept and print your grades of three courses (type: int) Third method to overload the second method (types: double). The method must print your grades. Call the three methods you created above in your main method. Create a method without parameters that would return only your GPA. The method should be named with your last name followed by GPA (e.g., AlwalledGPA()). Declare a double variable that holds the returned value of the last method you created. Print the value of your GPA variable. I attached Typical run of the programarrow_forward1. Write a Java program that will ask the a user a number between 1 to 7. 2. Print out the equivalent day of the week for that number. Starting 1 for Sunday, 2 for Monday and etc. 3. Use at least 1 user-defined method aside from your main method in writing a code for this problemarrow_forwardQ7. Write a program on value passing from one method to another and also write separate programs forA. Value passing from one class to anotherB. Multiple value passing from one method to another. Write above programms in Java Language.arrow_forward
- Using java Create a class that has one method. The method has parameters for prelim, midterm and final grades. It will display if the student passed or failed. (Passing is 70). Test the program for three students (three objects)arrow_forwardJAVA programming languagearrow_forwardjava Finish the method called profit() that will take two int arguments and returns a String saying if there is a profit, a loss, or no loss. The first argument is the buyPrice value and the second argument is the sellPrice value. There is a profit if the sell price is more than the buy price. This is a return method with two int parametersarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT