Skip to content
Advertisement

Display all the items I have 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;
     }
   }

Advertisement

Answer

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
...
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement