收銀員收款程式,收銀員收款

來源:互聯網
上載者:User

收銀員收款程式,收銀員收款

》題目要求:

  》》編寫一個收銀櫃檯收款程式。
    》》》要求:接收使用者輸入的商品單價、購買數量以及使用者付款的金額
    》》》計算並輸出八折以後的商品金額和找零

 

》程式實現

 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 : 待最佳化中......

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.