我有这四门课。我要做的是使用 customerID 将“Liftcard”添加到“用户”。这是我到目前为止得到的,但它似乎不起作用。我很确定问题出在窗口类中的公共 void regLiftCard() 方法中。有人知道我应该怎么做吗?(我使用数组列表)
用户等级:
public class User implements Serializable {
private String surename, firstName, gender, age;
private int customerID;
public LiftCard liftCard;
User next;
同班:
public LiftCard getLiftCard(){
return liftCard;
}
public void setLiftCard(LiftCard liftC){
liftCard = liftC;
}
窗口类:
public void regLiftCard()
{
int cardtype = Integer.parseInt(cardTypeField.getText());
int customerID = Integer.parseInt(findCustomerField.getText());
if(cardtype == 1 || cardtype == 2 || cardtype == 3 || customerID != 0)
{
//JOptionPane.showMessageDialog(this, "Du må fylle inn hvilket kort du skal ha 1/2/3");
try
{
User uu = userA.findById(customerID);
if (uu != null) {
if (uu.getLiftCard() != null) {
JOptionPane.showMessageDialog(this, "Kunden har allerede kort");
}
}
String fornavn = firstNameField.getText();
String etternavn = surenameField.getText();
String alder = ageField.getText();
String kjonn = genderField.getText();
LiftCard c = new LiftCard(cardNumber, cardtype);
if (userA.findByCardNumber(cardNumber) == null) {
uu.setLiftCard(c);
} else {
uu = new User(customerID, fornavn, etternavn, alder, kjonn);
}
JOptionPane.showMessageDialog(this, "Nytt kort/kunde er registrert");
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, "Feil i nummerformat!");
}
}
}
用户存档类:
public void regLiftCard(User u) {
list.add(u);
}
电梯卡类:
private int cardNumber, cardType;
public LiftCard(int cN, int cT)
{
cardNumber = cN;
cardType = cT;
}
public int getCardNumber(){
return cardNumber;
}
public int getcardType(){
return cardType;
}
public String toString()
{
return cardNumber + "\t" + cardType;
}
}