CashMachine (14)

1. В LoginCommand, WithdrawCommand добавь поле private ResourceBundle res, которое инициализируй соответствующим ресурсом.

Для LoginCommand ресурс login_en.properties.

Для WithdrawCommand ресурс withdraw_en.properties.



2. Для ресурса common_en.properties замени все строки в ConsoleHelper.

Для этого создай приватное статическое поле ResourceBundle res в классе ConsoleHelper и инициализируй соответствующим ресурсом.

Важно: путь к ресурсам строй динамически, для этого используй у класса CashMachine метод getPackage()





Требования:

1.LoginCommand должен содержать приватное поле ResourceBundle res.

2.WithdrawCommand должен содержать приватное поле ResourceBundle res.

3.ConsoleHelper должен содержать приватное статическое поле ResourceBundle res.

4. Поле res класса LoginCommand должно быть проинициализировано из файла login_en.properties.

5. Поле res класса WithdrawCommand должно быть проинициализировано из файла withdraw_en.properties.

6. Поле res класса ConsoleHelper должно быть проинициализировано из файла common_en.properties.

7. В методе execute() классов LoginCommand, WithdrawCommand используй вызовы соответствующих новых ресурсов.
class LoginCommand implements Command {
    private ResourceBundle validCreditCards = ResourceBundle.getBundle(CashMachine.RESOURCE_PATH + "verifiedCards");
    private ResourceBundle res = ResourceBundle.getBundle(CashMachine.RESOURCE_PATH + "login_en");

    @Override
    public void execute() throws InterruptOperationException
    {
        ConsoleHelper.writeMessage(res.getString("before"));
        while (true)
        {
            ConsoleHelper.writeMessage(res.getString("specify.data"));
            String s1 = ConsoleHelper.readString();
            String s2 = ConsoleHelper.readString();
            if (validCreditCards.containsKey(s1))
            {
                if (validCreditCards.getString(s1).equals(s2))
                    ConsoleHelper.writeMessage(String.format(res.getString("success.format"), s1));
                else
                {
                    ConsoleHelper.writeMessage(String.format(res.getString("not.verified.format"), s1));
                    ConsoleHelper.writeMessage(res.getString("try.again.or.exit"));
                    continue;
                }
            }
            else
            {
                ConsoleHelper.writeMessage(String.format(res.getString("not.verified.format"), s1));
                ConsoleHelper.writeMessage(res.getString("try.again.with.details"));
                continue;
            }

            break;
        }

    }
}
class WithdrawCommand implements Command
{
    private ResourceBundle res = ResourceBundle.getBundle(CashMachine.RESOURCE_PATH + "withdraw_en");
    @Override
    public void execute() throws InterruptOperationException
    {
        ConsoleHelper.writeMessage("Enter currency code");
        String currencyCode = ConsoleHelper.askCurrencyCode();
        CurrencyManipulator currencyManipulator = CurrencyManipulatorFactory.getManipulatorByCurrencyCode(currencyCode);
        int sum;
        while(true)
        {
            ConsoleHelper.writeMessage(res.getString("before"));
            String s = ConsoleHelper.readString();
            try
            {
                sum = Integer.parseInt(s);
            } catch (NumberFormatException e)
            {
                ConsoleHelper.writeMessage(res.getString("specify.amount"));
                continue;
            }
            if (sum <= 0)
            {
                ConsoleHelper.writeMessage(res.getString("specify.not.empty.amount"));
                continue;
            }
            if (!currencyManipulator.isAmountAvailable(sum))
            {
                ConsoleHelper.writeMessage(res.getString("not.enough.money"));
                continue;
            }
            try
            {
                currencyManipulator.withdrawAmount(sum);
            } catch (NotEnoughMoneyException e)
            {
                ConsoleHelper.writeMessage(res.getString("exact.amount.not.available"));
                continue;
            }
            ConsoleHelper.writeMessage(String.format(res.getString("success.format"), sum, currencyCode));
            break;
        }

    }
}
withdraw_en.properties
before=Withdrawing...
success.format=%d %s was withdrawn successfully
specify.amount=Please specify integer amount for withdrawing.
specify.not.empty.amount=Please specify valid positive integer amount for withdrawing.
not.enough.money=Not enough money on your account, please try again
exact.amount.not.available=Exact amount is not available
login_en.properties
before=Logging in...
specify.data=Please specify your credit card number and pin code or type 'EXIT' for exiting.
success.format=Credit card [%s] is verified successfully!
not.verified.format=Credit card [%s] is not verified.
try.again.or.exit=Please try again or type 'EXIT' for urgent exiting
try.again.with.details=Please specify valid credit card number - 12 digits, pin code - 4 digits.
как ни крути, 7-ой пункт не проходит