嗨,大家好,我正嘗試使用我的帳號登錄到一個數組列表,我無法將用戶輸入與帳號相匹配。我的代碼如下:如何用賬號登錄-Just
登錄方法,主類
private void Login(){
int UserInput;
Scanner option = new Scanner (System.in);
Account Account = new Account();
ArrayList<Client> customers = bank.getCustomers(); //Gets Customer Info from Bank
System.out.println("What is your Account Number?");
UserInput = option.nextInt();
if(UserInput==Account.getAccountNumber()){
Menu();
int choice = UserInput();
performAction(choice);
//system.out.println(i+1 + ")" + customers.get(i).BasicInfo());
}
else {
System.out.println("Invalid Account Number");
}
}
的ArrayList - 銀行類
public class Bank {
ArrayList<Client> customers = new ArrayList<Client>(); //Adds customer details in this
void addCustomer(Client customer) {
// TODO Auto-generated method stub
customers.add(customer);//Adds customer from Menu to ArrayList
}
Client getCustomer(int account) {
// TODO Auto-generated method stub
return customers.get(account); //Returns Customer detail from ArrayList
}
ArrayList <Client> getCustomers(){
return customers; //Returns customers
}
}
嗨,大家好,我想要做的就是讓主類中的用戶輸入能夠匹配來自'GetMethod'的AccountNumber,我相信它存儲在'Bank'類的araylist中。如果它匹配帳號,則其他方法在if語句中起作用。現在,當我輸入AccountNumber時,它會轉到else語句並顯示「Invalid AccountNumber」。如果這沒有意義,我很抱歉。
帳戶帳戶=新帳戶();不要使用類名來標識對象。 – TheMirrox
或者只是使用適當的java命名標準.. –