Ask Question
4 July, 23:24

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

+4
Answers (1)
  1. 5 July, 01:38
    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “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 ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers