2

I am supposed to let up to 16 guests order wine from a menu like this:

enter image description here The program has to be modular. To place an order, the guest must be shown a list of product types and then variations based on that type. Once the orders are processed I have to show a final report with: total amount made by the winery, most ordered wine product type, and the wine product/variation combo ordered the most times.

I am not sure how to make a method that will search the counter array for the most ordered product type, and then another method that will search the counter array for the most ordered product/variation combo. That is what I need help with.

import javax.swing.JOptionPane;

public class Wine_Taste{
public static void main(String[] args){

  String[]wines = {"Riesling", "Chardonnay", "Sauvignon Blanc", "Merlot"};
  String[][]wineTypes= 
                       {{"Dry- $4.50", "Off Dry-$4.00", "Sweet- $5.00",},
                       {"Apple- $6.00", "Lemon-$5.50","Vanilla- $6.00"},
                       {"Lime-$4.50", "Lemongrass- $6.50","Coconut- $7.00"},
                       {"Plum- $5.00", "Black Cherry- $7.50","Chocolate- $6.00"}};
 }

 double[][]prices= {{4.50, 4.00, 5.00},
                 {6.00, 5.50, 6.00},
                 {4.50, 6.50, 7.00},
                 {5.00, 7.50, 6.00}};

 int[][]counter ={{0,0,0},
                  {0,0,0},
                  {0,0,0},
                  {0,0,0}};

 counter = go(wines,wineTypes,counter,prices); 



public static int[][] go(String[] wines, String[][] wineTypes, int[][] counter, double[][] prices){ 
go2(counter);
double totalCost = 0; 
String user; 
int x =0; 
  while (x<=16){ 
     for(int i = 0;i<wines.length;i++){ 
        JOptionPane.showMessageDialog(null,wines[i]); 
     } 
     user = JOptionPane.showInputDialog("choose wine 0-3"); 
     int i = Integer.parseInt(user); 
        for(int j=0;j<wineTypes[i].length;j++){ 
           JOptionPane.showMessageDialog(wineTypes[i][j]); 
        } 
           user = JOptionPane.showInputDialog("choose option 0-3"); 
           int j = Integer.parseInt(user); 
           totalCost += prices[i][j]; 
           counter[i][j]++; 
           user = JOptionPane.showInputDialog("Order more? y/n"); 
                 if (user.equals("y")){ 
                    x++; 
                 else{ 
                 JOptionPane.showMessageDialog(totalCost); 
              } 
             }     
            } 
            return counter;
           }
          }
         }
Hello
  • 113
  • 8
  • There is no actual question here... Anyway, my advice is not leave programming practices until there are only 3 hours left. – SJuan76 Dec 13 '15 at 00:38
  • I forgot to put my question, sorry. And, some things went wrong today, usually these are due by sunday night, I also had 4 finals in a row and never got around to it on top of it all. – Hello Dec 13 '15 at 00:40
  • I strongly encourage you to learn how to indent code properly – TheQAGuy Dec 13 '15 at 00:43

1 Answers1

1

I wouldn't design the program like that. Following some basic object oriented dev principles you can have a wine class with a wine type, price etc, for example:

public class Wine {

    String name;
    String type;
    double price;

    public Wine(String name, String type, double price) {
        super();
        this.name = name;
        this.type = type;
        this.price = price;
    }

    //+getters setters

}

Then you can have an order class that keeps the order specific data, like which wine was ordered, the total price etc.

If for any reason you want to keep using the approach of multiple (not easy to manage) arrays then I guess you can create a hashmap where the keys are the wine names and the values the popularity. You can increment by one when a new wine is ordered. You can increment as here:

How to update a value, given a key in a java hashmap?

If for any reason you don't want or can't use this approach then you can create two functions: getPopularProductVarCombo() for the most ordered type per wine, and getMostPopular() for the most popular of all.

To implement getMostPopular you have to find the max value of the array. Here is a good example on how to do this

Print largest number in a 2d array - why do my code print three numbers

To implement getPopularProductVarCombo() then find the max value per line. Any other additional info you might need can be fetched in a similar way.

Community
  • 1
  • 1
jedidog
  • 260
  • 1
  • 7
  • I can't use objects :( I can't use hashmaps, I can't use break, I can't use system.exit, I can only use JOptionPane...I should have told you – Hello Dec 13 '15 at 01:13