Please write this in JAVA ONLY Thank you Write a program tha
Please write this in JAVA ONLY! Thank you!
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.
Your output should be formatted in such a way that it makes sense for what you as a user would want to see. Remember to Output what a description of what you are showing the user - not just values on a screen.
Solution
package org.students;
import java.util.Scanner;
public class CalGratuity {
public static void main(String[] args) {
//Declaring variables
double subtotal,gratuity_rate,total,gratuity_amt;
//Scanner class object is used read the inputs entered by the user
Scanner sc=new Scanner(System.in);
//Getting the subtotal Entered by the user
System.out.print(\"Enter Subtotal :$\");
subtotal=sc.nextDouble();
//Getting the gratuity rate entered by the user
System.out.print(\"Enter Gratuity Rate :%\");
gratuity_rate=sc.nextDouble();
//calculating the gratuity amount
gratuity_amt=subtotal*(gratuity_rate/100);
//calculating the total amount
total=subtotal+gratuity_amt;
//Displaying the subtotal entered by the user
System.out.printf(\"Sub Total \\t\\t:$%.2f\",subtotal);
//Displaying the gratuity amount
System.out.printf(\"\ Gratuity Amount \\t:$%.2f\",gratuity_amt);
//Displaying the total amount
System.out.printf(\"\ Total Amount\\t \\t:$%.2f\",total);
}
}
________________________________________
Output:
Enter Subtotal :$10
Enter Gratuity Rate :%15
Sub Total :$10.00
Gratuity Amount :$1.50
Total Amount :$11.50
_______________________________Thank You

