计算小费

import javax.swing.JOptionPane;
public class Money {
    public static void main(String[] args){
    double gratuity;
    double total;
    String input = JOptionPane.showInputDialog(null,"请输入费用:","对话框",JOptionPane.QUESTION_MESSAGE);
    String input1 =JOptionPane.showInputDialog(null,"请输入酬金:","对话框",JOptionPane.QUESTION_MESSAGE);
    double subtotal = Double.parseDouble(input);
    double rate = Double.parseDouble(input1);
    gratuity = (int)(subtotal * rate * 0.01 * 100)/100.00;
    total =(int)((subtotal + gratuity)*100)/100.00;
    System.out.println("The grtuity is " + gratuity + " and total is " + total);
    }
}

读入一笔费用与酬金率,计算酬金和总金钱数。例如,如果用户输入10作为费用,15%作为酬金率,计算显示酬金¥1.5,总费用为¥11.5。

posted @ 2014-08-06 14:49  Amoxicil  阅读(283)  评论(0编辑  收藏  举报