Basically whenever the user clicks on option 2 in the main menu they get to deposit funds into an account of their choice. (This is my code for option 2).. For this example lets say we have 3 accounts. '1001', '1002' and '1003' this is their ID's. So i have this for loop which loops through the array of accounts which is called 'businesses' and has an if statement to see if the account exists or not.
System.out.println("Enter account you wish to deposit into: ");
depositRef = input.nextInt();
for(int i = 0; i < businesses.members.size(); i++) {
//System.out.println(businesses.getCurrent(i).getAccRefNo()); a check to make sure all accounts exist. which they do.
if (depositRef == businesses.getReferenceNo(i)) {
System.out.println("Enter the amount you wish to deposit into " + businesses.getCurrent(i).getName() + "'s account: ");
balance = input.nextDouble();
businesses.getCurrent(i).deposit(balance);
} else if (depositRef != businesses.getReferenceNo(i)) {
System.out.print("Sorry Account doesnt exist. Try again!");
return;
}
}
break;
My problem being is that if we Entered '1003' the for loop will not keep looping until it reaches '1003' it will just say sorry account doesnt exist! how do i ammend this code so that it loops through until it matches? it only loops once and if it doesnt match '1001' then it throws an error.
If you think this question is missing anything that might help just say and ill happily add it in.
Aucun commentaire:
Enregistrer un commentaire