Fill This Form To Receive Instant Help
Homework answers / question archive / Write a program that reads the subtotal and the gratuity rate, and computes the gratuity and total
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 subtotal and 15% for gratuity rate, the program displays $1.5 as gratuity and $11.5 as total.
Answer:
public class Exercise2_5 {
public static void main(String args[]) {
// Read subtotal
java.util.Scanner input = new java.util.Scanner(System.in); System.out.print("Enter subtotal: ");
double subtotal = input.nextDouble();
// Read subtotal
System.out.print("Enter gratuity rate: "); double rate = input.nextDouble();
double gratuity = subtotal * rate / 100; double total = subtotal + gratuity;
System.out.println("Gratuity is " + gratuity); System.out.println("Total is " + total);
}
}