1. 程式人生 > 其它 >專案 1 計算購買文具的總費用

專案 1 計算購買文具的總費用

技術標籤:# 專案java專案計算購買文具的總費用

專案 1 計算購買文具的總費用

  • 請編寫一個 Java 應用程式,讀取某文具店的文具訂單數量,計算當前訂單的總費用。
    假設該文具店只出售作業本和筆:每個作業本 0.50 元,每支筆 2.75 元。
    程式執行的效果如下圖所示:
    在這裡插入圖片描述
    在這裡插入圖片描述
    在這裡插入圖片描述

  • 參考程式碼:

    package FirstProject;
    
    import javax.swing.*;
    
    public class LuoYu_1 {
        public static void main(String[] args) {
            String number;
            double
    number1, number2, sum = 0; // read in numbers from user as strings and convert to ints number = JOptionPane.showInputDialog(null, "Enter the number of notebook"); number1 = Integer.parseInt(number); number = JOptionPane.showInputDialog(null, "Enter the number of pen"
    ); number2 = Integer.parseInt(number); // compute sum sum = number1 * 0.5 + number2 * 2.75; // display the sum JOptionPane.showMessageDialog(null, "The total order cost is ¥" + sum, "總費用", JOptionPane.PLAIN_MESSAGE); // terminate the program
    System.exit(0); } }