Witam, mam problem w swojej aplikacji otóż gdy tworzę konto dla klienta banku to przy jego wyświetleniu pokazuje mi numer konta jego saldo ale brak imienia klienta i tak już siedzę i próbuje drugi dzień coś zdziałać ale nie mam pojęcia o co chodzi.
public class AccountList
{
private ArrayList <Account> newAccount = new ArrayList<Account>();
//Funkcja dodaj konto:
public boolean addAccount (Account newAcc){
if (findAccount(newAcc.getUserName()) >= 0){ // getScurityNo changed to getUserName.
System.out.println("Cannot create account due to Security Number error.");
return false;
}
this.newAccount.add(newAcc);
return true;
}
//Funkcja znajdź konto:
private int findAccount (Account acc){
return newAccount.indexOf(acc);
}
private int findAccount (String userName){
for (int i = 0; i < newAccount.size(); i++){
Account acc = newAccount.get(i);
if (acc.getUserName().equals(userName)){
return i;
}
}
return -1;
}
public String queryAccount (Account acc){
if (findAccount(acc) >= 0){
return acc.getUserName();
}
return null;
}
/*private int findAccount (int securityNo){
for (int i = 0; i < newAccount.size(); i++){
Account newAcc = newAccount.get(i);
if (newAcc.getSecurityNumber() == securityNo){
return i;
}
}
return -1;
}*/
//Funkcja usuń konto:
public void removeAccount (int securityNo){
for (int i = 0; i < newAccount.size(); i++){
Account newAcc = newAccount.get(i);
if (securityNo == newAcc.getSecurityNumber()){
newAccount.remove(newAcc);
}
}
}
//Funkcja wyświetl wszystkie konta:
public void showAllAcc (){
for (int i = 0; i < newAccount.size(); i++){
System.out.println((i+1) + ". \nName: " + newAccount.get(i).getUserName() + "\nAccount number: " + newAccount.get(i).getAccountNo() + "\nBalance: " + newAccount.get(i).getBalance());
}
}
}
public class Account
{
private String userName;
private long accountNo;
private int securityNumber;
private double random = Math.random();
private double balance;
public Account (String userName, double balance, int securityNumber){
this.userName= userName;
this.accountNo = (long)(random*(Math.pow(10,16)));
this.balance= balance;
this.securityNumber = securityNumber;
}
public String getUserName() {
return userName;
}
public long getAccountNo() {
return accountNo;
}
public double getBalance() {
return balance;
}
public int getSecurityNumber() {
return securityNumber;
}
public static Account createAccount (String userName, double balance, int securityNumber)
{
return new Account(userName,balance, securityNumber);
}
}