In part 11, we hardcoded the credit card number and PIN code used to allow working with our ATM.
But we could have lots of users. We certainly won't hardcode them all! If we need to add another user, we would have to redeploy our application. There is a solution to this problem.
Note that a new resources package has been added. We'll store our resource files in it.
This package has the verifiedCards.properties file, where card numbers and PIN codes are specified.
1. Add a private ResourceBundle validCreditCards field to LoginCommand.
In the declaration, initialize this field with the data from the verifiedCards.properties file.
Read online to find out how this is done for a ResourceBundle.
Important: build the path to verifiedCards.properties dynamically using the CashMachine class's getPackage() method
2. Replace the hardcoded credit card and PIN data with a check to see whether the entered user data is in verifiedCards.properties.
Requirements:
LoginCommand must have a private ResourceBundle validCreditCards field.
The validCreditCards field must be initialized from the verifiedCards.properties file.
Check credit cards and PIN codes using verifiedCards.properties.
package com.codegym.task.task26.task2613;
public enum Operation {
LOGIN,
INFO,
DEPOSIT,
WITHDRAW,
EXIT;
public static Operation getAllowableOperationByOrdinal(Integer i) {
switch(i) {
case 1: return INFO;
case 2: return DEPOSIT;
case 3: return WITHDRAW;
case 4: return EXIT;
}
throw new IllegalArgumentException();
}
}