Ask 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 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

+5
Answers (1)
  1. 8 November, 12:07
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers