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