收银员收款程序
》题目要求:
》》编写一个收银柜台收款程序。 》》》要求:接收用户输入的商品单价、购买数量以及用户付款的金额 》》》计算并输出八折以后的商品金额和找零
》程序实现
package cn.fury.test; import java.util.Scanner; public class Test{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Please input the quantity of your goods:"); int quantity = sc.nextInt(); System.out.println("Please input the price of your goods:"); float price = sc.nextFloat(); System.out.println("Please input the payment amount:"); float payment_amount = sc.nextFloat(); System.out.println("The money that you should pay is :" + price * quantity); System.out.println("The money that the salesclerk should return you: " + (payment_amount - price * quantity)); } }View Code
》程序改进方案:
》》收银员可以输入多种商品,输入end时表示结束输入
》》依次输入每种商品的价格,输入前提示是什么商品
》》计算所有商品的总金额
》》根据总金额决定折扣,100以下不打折,如果超过100就打8折,超过200就打7折,300以上打6折
》》返回打折后的总金额以及找零金额
》》notice : 待优化中......
相关推荐
匀矢覌泽 2017-12-03