【发布时间】:2015-08-25 06:54:07
【问题描述】:
我想在不使用扩展的情况下将Customer 类的属性添加到Booking 类,因为Customer 是Booking 的属性而不是扩展。如何以最好的方式做到这一点?
public class Booking implements Serializable{
private String flighttime;
private String flightlocation;
private String flightfee;
private boolean car;
private boolean insurance;
private Customer customer;
...
}
public class Customer extends Person implements Serializable {
private String passportID;
private String consultantname;
private String consultantsurname;
private String consulid;
....
}
private void savebookingButtonActionPerformed(java.awt.event.ActionEvent evt) {
Booking customerbooking = new Booking();
try {
if (custnameTF.getText().equals("")) {
throw new EmptyField("Please Insert Customer");
} else {
FileOutputStream fos = new FileOutputStream(
"Bookings/" + custidTF.getText() + ".txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
customerbooking.setPersonName((custnameTF.getText()));
customerbooking.setPersonSurname((custsurnameTF.getText()));
customerbooking.setPersonID((custidTF.getText()));
customerbooking.setConsultantname(consnameTF.getText());
customerbooking.setConsultantsurname((conssurnameTF.getText()));
customerbooking.setConsulid(considTF.getText());
customerbooking.setFlightlocation(locationCB.getSelectedItem().toString());
customerbooking.setFlighttime(timeCB.getSelectedItem().toString());
customerbooking.setFlightfee(feeCB.getSelectedItem().toString());
customerbooking.setCar(carRB.isSelected());
customerbooking.setInsurance(insuranceRB.isSelected());
}
}
}
【问题讨论】:
-
book.getCustomer().getPassportID()
标签: java class inheritance properties