 Computers and Technology
28 August, 06:51

# Write a program that reads the subtotal and the gratuity rate and computes the gratuity and total. For example, if the user enters 10 for the subtotal and 15% for the gratuity rate, the program displays 1.5 as the gratuity and 11.5 as the total. Here is another sample run:Enter the subtotal and a gratuity rate:The gratuity is 2.35 and the total is 18.04

+3
1. 28 August, 08:40
0
import java. util. Scanner;

public class ANot {

public static void main (String[] args) {

Scanner in = new Scanner (System. in);

System. out. println ("Enter the Sub-total and Gratuity rate");

double subTotal = in. nextDouble ();

int gratuityRate = in. nextInt ();

double rate = gratuityRate/subTotal;

double total = subTotal+rate;

System. out. println ("The Gratuity is "+rate+" and the total is " + total);

}

}

Explanation:

The code snippet above accomplishes the task. We prompt user to enter the values for subTotal and gratuityRate using Java's Scanner class and store the values in the variables respectively. Next we create two new variables to hold the rate and total, we understand from the question that the rate = gratuityRate/subTotal and the total = subTotal+rate.