英文:
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<String>
and every time you click on a product you do list.add('Cookies')
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
...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论