2.5 (财务应用程序:计算小费)编写一个程序,读入一笔费用与酬金率,计算酬金和总钱数。例如,如果用户输入10作为费用,15%作为酬金率,计算结果显示酬金为$1.5,总费用为$11.5。
import java.util.Scanner;
public class ComputeFee
{
public static void main(String[] args)
{
Scanner inPut = new Scanner(System.in);
//displat prompt
System.out.println("Enter the subtotal and a gratuity rate:");
double subtotal = inPut.nextDouble();
double gratuityRate = inPut.nextDouble();
//compute the gratuity and total
double gratuity = subtotal*gratuityRate/100;
double total = gratuity+subtotal;
//display result
System.out.println("The gratuity is $"+gratuity+" and total is $"+total);
}
}