2013-12-09 2 views
0

내 클래스의 내 드라이버 파일입니다. 다른 클래스에 이미 액세스하고 있지만, 내 비행기 클래스에 액세스해야합니다. 운전석에 비행기 클래스를 통합하려면 어떻게해야합니까?클래스를 내 드라이버 클래스로 호출하려면 어떻게해야합니까?

import java.util.ArrayList; 
import java.util.Scanner; 

public class Reservations { 
public static void main(String[] args) { 
    Plane airline = new Plane("American Airlines 19", "tommorow", 21, 4); 
    ArrayList<Passenger> list = new ArrayList<Passenger>(); 
    Scanner keyboard = new Scanner(System.in); 

boolean done = false; 
     while(!done) { 
      System.out.print("Please enter a passenger name(-1 to quit): "); 
      String name = keyboard.next(); 
       if(name.equals("-1")) { 
        done = true; 
       } 
       else { 
        System.out.print("Please enter the seating preference: "); 
        String seating = keyboard.next(); 
        char seat = seating.charAt(seating.length() - 1); 
        int row = Integer.parseInt(seating.substring(0, seating.length() - 1)); 
        boolean found = false; 
       for(AvilaNatalyPassenger x: list) { 
        if(name.equals(x.getName())) { 
         found = true; 
         x.setPreference(row, seat); 
        } 
       } 
       if(!found) { 
       list.add(new AvilaNatalyPassenger(name,row,seat)); 
      } 
      } 
     } 
    } 
} 

이것은 내 비행기 클래스입니다. 드라이버에 어떻게 연결합니까?

class Plane { 
private int[][] seats; 
String flight; 
String departure; 

public Plane(String name, String leaving, int length, int width){ 
    flight = name; 
    departure = leaving; 
    for(length = 0; length < 22; length++) 
     for(width = 0; width < 5; width++) 
      seats[length][width] = -1; 
} 

public String getFlight() { 
    return flight; 
} 
public String getDepartureTime() { 
    return departure; 
} 
public void setDepartureTime(String newTime) { 
    this.departure = newTime; 
} 
public boolean makeReservation(int id, AvilaNatalyPassenger request) { 
    boolean status = false; 
    int row = request.getRow(); 
     int seat = request.getSeatNumber(); 
     char seatCode = request.getSeatCode(); 

     switch(seat) { 
      case 0: seatCode = 'A'; break; 
      case 1: seatCode = 'B'; break; 
      case 2: seatCode = 'C'; break; 
      case 3: seatCode = 'D'; break; 
     } 

     if(getId(row, seat) == -1) { 
      for(int i=0; i < seats.length; i++) { 
       for(int j=0; j < seats[0].length; j++) { 
     if(seats[i][j] == id) { 
      seats[i][j] = -1; System.out.println("DELETING OLD RESERVATIONS. "); 
     } 
     } 
    } 

    System.out.println("ROW " + row + ", SEAT " + seatCode + " IS NOW RESERVED TO " + request.getName()); 
    seats[row][seat] = id; 
    status = true; 

} 
else { 
    System.out.println("SEAT IS ALREADY TAKEN. "); // see "main" in driver for alternate 
} 
return status; 
} 

public int getId(int row, int seat){ 
     if(row >= 0 && row < seats[0].length && seat >= 0 && seat < seats.length){ 
      return seats[row][seat]; 
     } 
     else{ 
      return -1; 
     } 
} 
public String getAssignment(int id){ 
char x; 
for (int i = 0; i < 21; i++) 
    for (int j = 0; j < 4; j++) 
    if (seats[i][j] == -1){ 
     if(j == 0) { 
       x = 'A'; 
      } 
      else if(j == 1) { 
       x = 'B'; 
      } 
      else if(j == 2) { 
       x = 'C'; 
      } 
      else if(j == 3) { 
       x = 'D'; 
      } 
    } 
return "((i+1) + x)"; 
} 
} 
+0

class Plane { 

당신은 드라이버 클래스에 의해 무엇을 의미합니까? –

+0

무엇을 의미합니까? * 운전 기사에게 비행기 클래스를 통합하는 방법은 무엇입니까? * – Lion

+0

주 예약 프로그램입니다. @AmirPashazadeh – user3026678

답변

0

Plane 클래스를 공용으로 설정해보십시오.

public class Plane { 
관련 문제