Ich habe eine Methode, die das bereitgestellte Bankkonto zu einem Array hinzufügen muss, die ich geschaffen habe:Hinzufügen eines Wertes zu einem Array
public boolean addAccount (BankAccount newAccount[]) {
if (numAccounts == 0) {
return false;
}
else {
return true;
for(int counter=0; counter<newAccount.length; counter++)
newAccount[counter] += accounts;
}
}
es durch dieses Verfahren getestet wird:
public static boolean test5() {
System.out.println("Test5: add an account to a customer.");
BankAccount b = new BankAccount();
Customer c1 = new Customer("Alice", "Smith");
customerCounter ++;
if (!c1.addAccount(b))
return false;
return c1.toString().equals("Alice Smith, " + c1.getCustomerID() + "\n" + b.toString() + "\n");
}
ich erhalte eine Fehlermeldung jedoch welche eclipse haben keine Lösung für in dieser Zeile:
newAccount[counter] += accounts;
Der Compiler sollte Sie über nicht erreichbaren Code warnen ('for' nach' return') – Turing85
Es wurde kein Fehler mit nicht erreichbarem Code erhalten. Ich habe es auf this.newAccount [counter] + = accounts; und jetzt bekomme ich eine Fehlermeldung, dass newAccount kein Feld ist. – Stavan
Beginnen Sie mit Java-Lernprogrammen wie https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html und https://docs.oracle.com/javase/tutorial/collections/TOC.html –