2013-10-04 1 views
0
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,"print"); 

내가 메뉴를 요구하고있다 :

JOptionPane.showMessageDialog(null,"sales"); 

는 또한 인쇄 섹션에서 내가 구입 한 항목에 대한 인쇄를 확인하기 위해 프로그램이 필요 : 여기 내 입력을 얼마나 모르겠어요 반복 할 수 있습니다. menulist == 1 menulist == 2에 인쇄 할 수 있습니다. 그게 다예요 :) < 이미 완료

+0

정확하게 무엇이 문제입니까? 컴파일 오류, 예외, 논리적 인 문제, ... –

+0

아무것도 입력을 얻는 방법을 모르겠다 그래서 항목과 그것의 가격을 볼 수 있도록 – bhw

+0

JOption의 String [] 목록 옵션을 원한다고 말하고 있습니까? 창유리? 또는 항목, 이름, 가격을 표시하고 싶습니다. e.t.c – Levenal

답변

0

이것은 원래 원하는 것이어야합니다. 옵션 1을 먼저 사용하여 '주문'을 작성합니다. 그런 다음 메뉴로 돌아가며 옵션 2와 3을 사용하여 메뉴를 볼 수 있습니다.

import java.util.ArrayList; 
import javax.swing.JOptionPane; 

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

    int MenuList; //Declared outside the loop, this will keep the variable in memory as we go through the program. 
    String myOrder = "No order currently set"; //Declared outside the loop for above reasons. This will become the order. 
do{ //Start of Do Loop, this will keep you going through the menu. 

    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]); 
    } 


    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]); 
     } 

     myOrder = ""; 
     ArrayList<String> Orders = new ArrayList<>(); 

     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"); 

      Orders.add("Item " + input + " Quantity " + itemq); 
     } 

     for(String s : Orders){ 
      myOrder += "\n" + s; 
     } 
    } else if(MenuList==2) {    
     JOptionPane.showMessageDialog(null,"sales \n" + myOrder); 
    } else if(MenuList==3) { 
     JOptionPane.showMessageDialog(null,"print"); 
     System.out.println(myOrder); 
    } else if(MenuList==4) { 
     JOptionPane.showMessageDialog(null,"Exit,Bye"); 
    } else { 
     System.out.print("Invalid"); 
    } 
      }while(MenuList != 4); //End of Do loop. Exiting program when selecting exit (Number 4) 
} 
} 
+0

uhm, array.list를 사용하여 내가 어떻게 항목을 만들 수 있도록 선택합니까 (menulist == 1) if (menulist == 2) joptionpane을 사용하지 않고 표시합니다. – bhw

+0

MenuList == 1에서 선택한 항목을 MenuList == 2에서 사용할 수 있도록 하시겠습니까? – Levenal

+0

예 thats 무엇을 목표로하고 있습니까 – bhw

관련 문제