2017-12-18 1 views
-1

현재 내가 가지고있는 것 : 나는 현재 사용자에게 인사하고 그들이 원하는 옵션에 대해 숫자 (1-10)를 입력하도록 요청하는 공용 클래스 "MainMenu"를 가지고 있습니다. 실행하다. 이것은 Switch case에 의해 선택됩니다.방법을 실행하고 '반환'을 검색 한 후 내 메인 메뉴로 돌아가려면 어떻게해야합니까?

각각의 경우에는 작은 실행을 실행하거나 별도의 클래스를 가리 킵니다. 이것은 10을 선택할 계속 나는 사용자를 메인 메뉴로 돌아 객체를 반환하고, 수 있도록하고 싶습니다 내 AddAirline 방법을 실행

public static void mainMenu(Scanner sc) { 
    //Scanner sc = new Scanner(System.in); 
    System.out.println("Welcome to the Flight Scheduler!\n"); 
    System.out.println("Please remember to always use U, M, T, W, R, F, S, for entering"); 
    System.out.println("the day of the week, and to always use military time"); 
    System.out.println("for entering the time."); 
    System.out.println("Please make your choice\nby entering the corresponding menu number:\n"); 

    System.out.println("1.\tSet Clock"); 
    System.out.println("2.\tClear Schedule"); 
    System.out.println("3.\tAdd Airline"); 
    System.out.println("4.\tAdd Flight"); 
    System.out.println("5.\tCancel Flight"); 
    System.out.println("6.\tShow Flight Info"); 
    System.out.println("7.\tShow Departures"); 
    System.out.println("8.\tShow Arrivals"); 
    System.out.println("9.\tFind Flights Between Two Airports"); 
    System.out.println("10.\tExit\n"); 

    int userChoice = sc.nextInt(); 

    switch (userChoice) { 
     case 1: 
     AirlineAircraftData.AddAirline(sc); 
     break; 

: 예를 들어

이전에 제공된 옵션들, 즉 AddAirline 메소드에서 요청 된 필드를 입력 한 직후. 내가 뭘하는지

public static A8AirlineAircraftData AddAirline(Scanner sc) { 
    sc.nextLine(); 
    System.out.println("Please enter the Airline name:"); 
    String airName = sc.nextLine(); 

    System.out.println("Please enter the Airline code:"); 
    String airCode = sc.nextLine(); 
    System.out.println("Please enter the Delta Aircraft:"); 
    String airCraft = sc.nextLine(); 
    System.out.println("Please enter the first class seat capacity:"); 
    int firstClass = sc.nextInt(); 
    System.out.println("Please enter the business class seat capacity:"); 
    int busiClass = sc.nextInt(); 
    System.out.println("Please enter the economy class seat capacity:"); 
    int econClass = sc.nextInt(); 
    System.out.println("Airline name: " + airName); 
    System.out.println("Airline code: " + airCode); 
    System.out.println("Delta Aircraft: " + airCraft); 
    //Splitting the first word from the rest of the string 
    String arr[] = airCraft.split(" ", 2); 
    String firstWord = arr[0]; 
    System.out.println(firstWord + " first class seat capacity: " + firstClass); 
    System.out.println(firstWord + " business class seat capacity: " + busiClass); 
    System.out.println(firstWord + " economy class seat capacity: " + econClass); 
    //Airline object 
    A8AirlineAircraftData airline = new A8AirlineAircraftData(airName, airCode, airCraft, firstClass, busiClass, econClass); 
    System.out.println(airName + " successfully added. Press Enter to continue."); 
    sc.nextLine();//Press Enter to continue 
    sc.nextLine(); 
    //A8MainMenu.mainMenu(sc); //return to main menu after Enter. 
    return airline; 

내가 신인 해요, 어떤 도움 주셔서 감사합니다 내가 많이 알고 여기

나는 사용자가이를 선택 후 통해 실행하는거야하는 방법입니다 반드시 의미가있는 것은 아닙니다.

+1

일반적으로 루프에서 주 메뉴를 실행하고 사용자가 종료를 선택할 때 루프를 종료합니다. –

+0

* A8MainMenu.mainMenu (sc); * 행을 사용할 수 없다고 들었습니다. 왜 이런 경우입니까? –

+0

더 많은 것을 스택에 넣기 때문에 좋지 않습니다. 그렇게하고 사용자가 메뉴를 충분히 살펴 본다면 결국에는 StackOverflowError가 발생합니다. –

답변

0

@D M 덕분에이 문제를 해결할 수있었습니다. 나는 전체 메인 메뉴를 '10'에서 끝나는 do-while 루프로 감쌌다.

관련 문제