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)
- Writing Methods that Return a Value in Java In this lab, you complete a partially written Java program that includes a method that returns a value. The program is a simple calculator that prompts the user for two numbers and an operator ( +, −, *, /,or% ). The two numbers and the operator are passed to the method where the appropriate arithmetic operation is performed. The result is then returned to the main() method where the arithmetic operation and result are displayed. For example, if the user enters 3, 4, and *, the following is displayed: 3.00 * 4.00 = 12.00 The source code file provided for this lab includes the necessary variable declarations, and input and output statements. Comments are included in the file to help you write the remainder of the program. Instructions Write the Java statements as indicated by the comments. Execute the program Tasks Defined performOperation() Input / output tests Multiplication input / output test Division input / output test Subtraction…arrow_forwardWriting Methods that Return a Value in Java In this lab, you complete a partially written Java program that includes a method that returns a value. The program is a simple calculator that prompts the user for two numbers and an operator ( +, −, *, /,or% ). The two numbers and the operator are passed to the method where the appropriate arithmetic operation is performed. The result is then returned to the main() method where the arithmetic operation and result are displayed. For example, if the user enters 3, 4, and *, the following is displayed: 3.00 * 4.00 = 12.00 The source code file provided for this lab includes the necessary variable declarations, and input and output statements. Comments are included in the file to help you write the remainder of the program. Instructions Write the Java statements as indicated by the comments. Execute the program USE THE GIVEN CODE // Calculator.java - This program performs arithmetic, ( +. -, *. /, % ) on two numbers // Input: Interactive. //…arrow_forwardWriting Methods that Return a Value in Java In this lab, you complete a partially written Java program that includes a method that returns a value. The program is a simple calculator that prompts the user for two numbers and an operator ( +, −, *, /,or% ). The two numbers and the operator are passed to the method where the appropriate arithmetic operation is performed. The result is then returned to the main() method where the arithmetic operation and result are displayed. For example, if the user enters 3, 4, and *, the following is displayed: 3.00 * 4.00 = 12.00 The source code file provided for this lab includes the necessary variable declarations, and input and output statements. Comments are included in the file to help you write the remainder of the program. Instructions Write the Java statements as indicated by the comments. Execute the program Tasks Defined performOperation() Input / output tests performOperation unit tests performOperation addition test performOperation…arrow_forward
- Java code. How to write a method readGrades with the output shown below.arrow_forwardWrite 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_forwardQuestion Two Write a java program that prints student's name, grades and GPA. You must do the following requirements: 1. Create three methods: a. First method to accept and print your first, last name, and GPA. 2. Call the three methods you created above in your main method. b. Second method Markt and print your grades Marks of three courses (type: int) 3. 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()). Note: c. Third method to overload the second method (types: double). The method must print your grades. 4. Declare a double variable that holds the returned value of the last method you created. 5. Print the value of your GPA variable. Help ● The class name of your Java program must be your first name. • Your answer should have the code as text as well as the screenshot of the program output (using your own name) as a part of your answer. Otherwise, zero marks will be awarded.…arrow_forward
- Task 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_forwardMethod Headings. Write the appropriate method headings using the provided method name for the following processes. 1. Calculate and return the sum of two decimal numbers - getSum. 2. Compute and return the average speed of a car, given the distance traveled (as type double) and traveling time (in hours and minutes, both of type int) - getAverageSpeed. 3. Given the radius of a circle, print the area of a circle - printArea. 4. Given a student's name and three test scores (of type int), print the student's name and average test score - printStudentDetails.arrow_forwardIn 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_forward
- In Java Language, Write a Program that will compute the total tuition fee of a student. Input the name and student number of the student. Input the subject enrolled, the number of units, and the cost per unit to compute the total tuitionNote* Use methods and constructorarrow_forwardDesign a class that holds the following personal data: name, address, age, and phone number. Write appropriate accessor and mutator methods. Also, design a program that creates three instances of the class. One instance should hold your information, and the other two should hold your friends’ or family members’ information. very basic Algorithm in pseudocode not python. Use fictitious information.arrow_forwardWrite 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_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