展示我已经订购的所有物品

huangapple go评论77阅读模式
英文:

Display all the items I have ordered

问题

如何在“销售报告文件”中显示我订购的所有商品?例如,每当我订购2个曲奇,它都会显示在销售报告文件中。我目前有这段代码...

private final Dispenser candy = new Dispenser(100, 50);
private final Dispenser chips = new Dispenser(100, 65);
private final Dispenser gum = new Dispenser(75, 45);
private final Dispenser cookies = new Dispenser(100, 85);
public int products;

private final JButton candyB;
private final JButton chipsB;
private final JButton gumB;
private final JButton cookiesB;

private class ButtonHandler implements ActionListener {
    public void actionPerformed(ActionEvent e) {
        switch (e.getActionCommand()) {
            case "Exit":
                System.exit(0);
            case "Candy":
                sellProduct(candy, "Candy");
                products++;
                break;
            case "Chips":
                sellProduct(chips, "Chips");
                products++;
                break;
            case "Gum":
                sellProduct(gum, "Gum");
                products++;
                break;
            case "Cookies":
                sellProduct(cookies, "Cookies");
                products++;
                break;
            case "Sales Report File":
                JOptionPane.showMessageDialog(null, "售出的商品列表:" + DISPLAY ALL THE ITEMS ORDERED,
                    "销售报告 ~ ", JOptionPane.PLAIN_MESSAGE);
                break;
        }
    }
}

(注意:DISPLAY ALL THE ITEMS ORDERED 部分应替换为您实际的代码来显示已订购的商品列表。)

英文:

How to display all the items I have ordered in "Sales Report File"? Like whenever I ordered 2 cookies, It will display on the Sale Report file. I have this code currently..

     private final Dispenser candy = new Dispenser(100, 50);
     private final Dispenser chips = new Dispenser(100, 65);
     private final Dispenser gum = new Dispenser(75, 45);
     private final Dispenser cookies = new Dispenser(100, 85);
     public int products;

     private final JButton candyB;
     private final JButton chipsB;
     private final JButton gumB;
     private final JButton cookiesB;


   private class ButtonHandler implements ActionListener
   {
     public void actionPerformed (ActionEvent e)
     {
        switch (e.getActionCommand()) 
        {
            case "Exit":
              System.exit(0);
            case "Candy":
                sellProduct(candy, "Candy");
                products++;
                break;
            case "Chips":
                sellProduct(chips, "Chips");
                products++;
                break;
            case "Gum":
                sellProduct(gum, "Gum");
                products++;
                break;
            case "Cookies":
                sellProduct(cookies, "Cookies");
                products++;
            case "Sales Report File":
               JOptionPane.showMessageDialog(null,"Items list sold + "+ DISPLAY ALL THE ITEMS ORDERED  
               ,"Sales Report ~ ",JOptionPane.PLAIN_MESSAGE)
                break;
     }
   }

答案1

得分: 0

如果您想要一个您已订购物品的文本列表,您只需创建一个 ArrayList<String>,每次点击一个产品时,执行 list.add('Cookies') 或其他产品的名称,具体取决于开关。通过这种方式,您将获得一个按时间顺序排列的产品列表。

输出将会类似于:

Cookies,
Candies,
Candies,
Gum,
Chips,
Gum,
...
英文:

If you want like a text list of what you have ordered, you can simply create an ArrayList&lt;String&gt; and every time you click on a product you do list.add(&#39;Cookies&#39;) or whatever the product is, depending on the switch. In this way you have a list ordered by time-ordered products.

The output would be something like:

Cookies,
Candies,
Candies,
Gum,
Chips,
Gum
...

huangapple
  • 本文由 发表于 2020年10月19日 20:50:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/64427699.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定