Write a program that reads the subtotal and the gratuity rate for a service. Compute the gratuity and the total. For example, if the user enters 10 for the subtotal and 15% as the gratuity rate, the program displays $1.5 as the gratuity and $11.5 as total. Your program should output the subtotal entered, the gratuity rate, the gratuity amount and the total amount due.
//Gratuity.java import java.util.Scanner; public class Gratuity { public static void main(String[] args) { Scanner input = new Scanner(System.in); double subtotal, gratuityRate, gratuity, total; System.out.print("Enter the subtotal: "); subtotal = input.nextDouble(); System.out.print("Enter the gratuity rate: "); gratuityRate = input.nextDouble(); gratuity = subtotal * (gratuityRate / 100); total = subtotal + gratuity; System.out.printf("The gratuity is $%.1f and total is $%.1f\n", gratuity, total); } }
Get Answers For Free
Most questions answered within 1 hours.