如何将我的班级称为我的班级?

时间:2013-12-09 04:21:13

标签: java class methods driver

这是我的类的驱动程序文件,它已经访问了另一个类,但我需要它来访问我的平面类。如何将我的飞机课程纳入驾驶员?

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

1 个答案:

答案 0 :(得分:0)

也许尝试将您的Plane类公开?

class Plane {

public class Plane {