2016-12-02 7 views
-2

2次元配列に問題があり、正しく出力されないため、プログラムが正常に動作していますが、飛行機着座チャートを水平に出力するケース4を選択すると、 。もし誰かが正しい方向に私を指すことができればそれはすばらしいでしょう!java飛行機着座チャートアレイ

public static void viewSeatingChartVertical(boolean seat[]){ 
    for(int i = 0; i < 10; ++i){ 
    for(int j = 0; j < 3; ++j){ 
     if(seat[((j + 1) + (i * 3)) - 1]) 
      System.out.print("x "); 
     else 
      System.out.print("o "); 
     } 
     System.out.println(); 
    } 
} 

public static void viewSeatingChartHorizontal(boolean seat[]){ 
       int [][] twoDim = new int [3][10]; 

       int a = (twoDim.length); 
       int b = (twoDim[0].length); 

       for(int i = 0; i < a; i++){ 
       for(int j = 0; j < b; j++) { 
       int x = 0; 
       twoDim[i][j] = x; 

      if(seat[((j + 1) + (i * 3)) - 1]) 
      System.out.print("x "); 
      else 
      System.out.print("o "); 
     } 
     System.out.println(); 
     } 
     } 


public static void main(String args[]){ 

    java.util.Scanner input = new java.util.Scanner(System.in);// if the system doesnt know the Scanner function it then looks to import it 

    boolean seating[] = new boolean[30];//declare the amount of seats available on the plane in an array 

    //display list of options - saving space make easier to read on smaller screen  
System.out.println("Please choose an option:"); 
System.out.println("1 for “first class”"); 
System.out.println("2 for “economy”"); 
System.out.println("3 to view seating chart"); 
System.out.println("4 to view seating horizontally chart"); 
System.out.println("0 to exit"); 
System.out.print("? "); 

    while(true){                       //loop while valid 
    int mOpt = input.nextInt();              //mOpt Menu Option - validate number entered, must be 0-4 
     switch (mOpt){ 
     case 0: System.exit(0); 
      break;                      //system exit 

     case 1:                       // first class seats 
     { 
     System.out.print("Which seat would you like (1-9)\n"); 
     int fcseat = input.nextInt(); 
      if(fcseat > 0 && fcseat <10){ 
       if(seating[fcseat - 1]){ 
       System.out.print("That seat is taken.\n"); 
       } 
       else{ 
       seating[fcseat - 1] = true; 
       System.out.print("Seat number " + fcseat + " was assigned.\n"); 
       } 
      } 
     } 
     break; 

     case 2:                       // economic seats 
     { 
     System.out.print("Which seat would you like (10-30)\n"); 
     int econSeat = input.nextInt(); 
      if(econSeat >= 10 && econSeat <= 30){                 // HAD 31 NOT 30. SMH 
       if(seating[econSeat - 1]){ 
       System.out.print("That seat is taken.\n"); 
       } 
       else{ 
       seating[econSeat - 1] = true; 
       System.out.print("Seat number " + econSeat + " was assigned.\n"); 
       } 
      } 
     } 
     break; 

     case 3:                       //printout of available seats vertically 
     { 
     viewSeatingChartVertical(seating); 
     } 
     break; 

     case 4:                       //printout of available seats horizontally 
     { 
     viewSeatingChartHorizontal(seating); 
     } 
     break; 

     default:                      //wrong format or number please try again 
     System.out.print("Sorry, Option not recognized, please Try again.\n"); 
    }  
    } 
} 
} 

答えて

0

プレーンの行と列を画面の行と列に混在させています。

あなたの水平出力は本当に複雑です。これは、垂直出力と同じくらい簡単でなければなりません。キーは垂直出力のコードを複製しますが、2つのforステートメントを逆にします。

for(int j = 0; j < 3; ++j) { 
    for(int i = 0; i < 10; ++i) { 

魔法のように動作します。

まあ、ほとんど仕事。これは、平面の左右を反転させます。最初のループを少し変更すれば、それも修正されます。生徒に残された

+0

ありがとうございます!そんなに私はそれを得た。 – corvo

関連する問題