收銀員收款程式,收銀員收款
》題目要求:
》》編寫一個收銀櫃檯收款程式。
》》》要求:接收使用者輸入的商品單價、購買數量以及使用者付款的金額
》》》計算並輸出八折以後的商品金額和找零
》程式實現
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 }View Code
》程式改進方案:
》》收銀員可以輸入多種商品,輸入end時表示結束輸入
》》依次輸入每種商品的價格,輸入前提示是什麼商品
》》計算所有商品的總金額
》》根據總金額決定折扣,100以下不打折,如果超過100就打8折,超過200就打7折,300以上打6折
》》返回打折後的總金額以及找零金額
》》notice : 待最佳化中......