我对 Java 很陌生,对编程也比较陌生。我有 3 个课程,它们是相连的。
第一类:飞行
public class Flight {
private int flightNumber;
Passenger passenger1 = null; // two objects?
Passenger passenger2 = null;
private int confirmedPassengers = 0;
Passenger bagsChecked;
//private boolean bagsLoaded;
public Flight(int fn, int cf){
flightNumber = fn;
//passenger1 = p1;
//passenger2 = p2;
confirmedPassengers = cf;
//bagsChecked = bc;
}
public boolean addPassenger(Passenger p){
if (confirmedPassengers == 0){
passenger1= p;
confirmedPassengers+=1;
System.out.println("P1 has been added.");
return true;
}
if (confirmedPassengers == 1){
passenger2 = p;
confirmedPassengers+=1;
System.out.println("P2 has been added");
return true;
}
else{
System.out.println("This passenger was not added because the capacity is full.");
return false;
}
}
}
第 2 类:乘客
public class Passenger {
private String name;
Flight flight;
private int bagsChecked;
private String confirmationNumber;
public Passenger(String n, Flight f, int b, String cn){
name = n;
flight = f;
bagsChecked = b;
confirmationNumber = cn;
}
public boolean hasConfirmation(){
if (confirmationNumber != null) {
return true;
}
else{
return false;
}
}
}
第 3 类:售货亭:
public class Kiosk {
private int kioskNumber;
public Kiosk (int k){
kioskNumber = k;
}
public void checkIn(Passenger p){
if (p.hasConfirmation() == true) {
addPassenger(p); // trying to add Passenger here
System.out.println("Passenger " + p.getName() + ""+ "added in at Kiosk1 ");
}
}
}
当乘客Passenger
在. 如何使用方法添加到?Flight
Kiosk
addPassenger
Flight
Passenger
Kiosk