【发布时间】:2016-03-18 17:36:18
【问题描述】:
我应该让最多 16 位客人从这样的菜单中点酒:
该程序必须是模块化的。要下订单,必须向客人展示产品类型列表以及基于该类型的变体。订单处理完毕后,我必须出示一份最终报告:酒厂生产的总金额、订购最多的葡萄酒产品类型以及订购次数最多的葡萄酒产品/品种组合。
我不知道如何创建一种方法来搜索计数器数组以查找最有序的产品类型,然后另一种方法将搜索计数器数组以查找最有序的产品/变体组合。这就是我需要帮助的地方。
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;
}
}
}
【问题讨论】:
-
这里没有实际问题...无论如何,我的建议是在只剩下 3 个小时之前不要离开编程实践。
-
我忘了提出我的问题,对不起。而且,今天有些事情出了问题,通常这些是在星期天晚上到期的,我也连续参加了 4 场决赛,但最重要的是一直没有解决。
-
我强烈建议您学习如何正确缩进代码