2013-12-09 67 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

你是什么驱动程序类是什么意思? –

+0

你是什么意思,“*我如何将我的飞机课程纳入司机?*” – Lion

+0

我的主要预订计划。 @AmirPashazadeh – user3026678

回答

0

也许试着让你的飞机课程公开吗?

class Plane { 

public class Plane { 
相关问题