|
Newbie search array question
Hello everyone,
Im still new to Java so this should be an easy question to answer but I am stuck. Any suggestions would be great!
I have two classes; KeypadDisplay and AccountRepository.
The KeyPadDisplay class has the following two methods in regards to the problem;
public void askUserToInsertDebitCard() {
//creates variable to hold user input
int ID;
//creates new scanner object with the title accountID
Scanner accountID = new Scanner(System.in);
//displays a message and sets the user output to the ID variable
displayMessage("Please insert debit card" +
" - Enter account ID (e.g., 1 or 2)");
ID = accountID.nextInt();
AccountRepository acount = AccountRepository.getInstance();
acount.getAcount(ID);
and the second method is
public void displayMessage(String msg) {
System.out.println(msg);
}
Ok so as you can see I am calling the AccountRepository.getAcount() method and using ID as the parameter. What I need to do is check the accountID the user enters with the array found in the AccountRepository class.
Here is the array from the AccountRepository class and the method I am calling.
private AccountRepository() {
int accountValue = 100;
int accountID=1;
for(int i=0; i< MAX_ACCOUNTS; i++){
accounts[i] = new Account(accountID++, accountValue+=100);
}
}
private static Account[] accounts = new Account[MAX_ACCOUNTS];
public coldbeveragejava.Account getAcount(int accountID) {
return null;
}
What I cannot figure out is what to add to the getacount method to get it to check the ID with the ID's found in the array and then returning the value back to the askUserToInsertDebitCardClass.
If my question does not make sense here are the exact instructions
"After the user gives the account ID to askUserToInsertDebitCard(), use the AccountRepository getAcount method to look up the account by ID and return an account object to askUserToInsertDebitCard(). Note, getAccount must match the account ID that it gets as a parameter against the stored accounts and return the first matching account."
Thanks to anyone who takes the time to read this,
Morgan
|