import javax.swing.JOptionPane;
public class market4 {
public static void main(String[] args) {
System.out.println("---MENU---");
String[] menu = {"[1]item list","[2]sales","[3]print","[4]exit"};
for (int i=0;i<4;i++) {
System.out.println(menu[i]);
}
int MenuList;
String MenuString = JOptionPane.showInputDialog(null, " Choose number: ");
MenuList = Integer.parseInt(MenuString);
if(MenuList==1) {
System.out.println();
String[] list = {"hotdog","donut","eggpie","pizza","lasagna"};
int[] cost = {5,15,25,35,45};
int[] selling = {10,20,30,40,50};
int[] qty ={5,5,5,5,5};
System.out.println("item"+"\tcost"+"\tSelling"+"\tinv qty");
for (int m=0; m<list.length;m++) {
System.out.println(list[m]+"\t"+cost[m]+"\t\t"+selling[m]+"\t\t"+qty[m]);
}
for (int i = 0; i < 5; i++) {
String input = (String) JOptionPane.showInputDialog(null,
"Select an Item", "Welcome " + "!",
JOptionPane.QUESTION_MESSAGE, null, list, "Hotdog");
String[] itemQuantity = { "1", "2", "3", "4", "5" };
String itemq = (String) JOptionPane.showInputDialog(null,
"Enter Quantity", "Welcome",
JOptionPane.QUESTION_MESSAGE, null, itemQuantity, "1");
}
} else if(MenuList==2) {
JOptionPane.showMessageDialog(null,"sales");
} else if(MenuList==3) {
JOptionPane.showMessageDialog(null,"print");
} else if(MenuList==4) {
JOptionPane.showMessageDialog(null,"Exit,Bye");
} else {
System.out.print("Invalid");
}
}
}
我刚刚制作了我的第一个数组程序。我不知道我如何在这里得到我的输入:
JOptionPane.showMessageDialog(null,"sales");
同样在打印部分,我需要该程序来打印我购买的物品:
JOptionPane.showMessageDialog(null,"print");
我要求菜单循环。menulist==1 打印在 menulist==2 中。就是这样:) <已经完成