"Hi, Amigo!"

"Hello, Captain Squirrels, sir."

"You're a good student. Well done, soldier!"

"Today you have a new secret mission: master finances."

"Hooray!!! I already know what I'll spend the money on!!!"

"Don't relax yet, soldier! Mastering finances means writing a new secret ATM program.

Big task: ATM software - 1

"Go see Secret Agent IntelliJ IDEA. You'll receive all of the instructions there."

"It shall be done, Captain!"

undefined
10
Task
Java Collections, level 9, lesson 15
Locked
CashMachine (part 1)
Let's write an ATM emulator. We will support the following operations: deposit money, withdraw money, and show the status of the ATM. We will also support multiple currencies. The ATM will operate using the banknotes we put into it.
undefined
10
Task
Java Collections, level 9, lesson 15
Locked
CashMachine (part 2)
1. Create two static methods in ConsoleHelper: 1.1 writeMessage(String message), which will write our message to the console. 1.2 String readString(), which will read a string from the console and return it.
undefined
20
Task
Java Collections, level 9, lesson 15
Locked
CashMachine (part 3)
1. Create CurrencyManipulator class that stores all the information about the selected currency. The class must have: 1.1 String currencyCode — currency code, i.e. USD. It consists of three letters. 1.2 Map denominations is a map of (denomination, quantity) pairs.
undefined
40
Task
Java Collections, level 9, lesson 15
Locked
CashMachine (part 4)
1. Let's decide what operation to start with. Think about it. The ATM doesn't have money yet, so we can't test INFO and WITHDRAW. We'll start with the DEPOSIT operation. We read the currency code from the console. Then we read the denomination and number of banknotes.
undefined
20
Task
Java Collections, level 9, lesson 15
Locked
CashMachine (part 5)
1. In the previous task, we implemented the basic logic of the DEPOSIT operation. But we couldn't see the results. So, in the manipulator, create an int getTotalAmount() method that calculates the total amount for the selected currency. 2. Call the getTotalAmount() method in the main method.
undefined
20
Task
Java Collections, level 9, lesson 15
Locked
CashMachine (part 6)
To refactor the code according to the Command pattern, you need to extract several logical blocks of code. For now, we have two such blocks: 1) code for the DEPOSIT operation, 2) code for the INFO operation. This code is in the main method. We need to get rid of it.
undefined
20
Task
Java Collections, level 9, lesson 15
Locked
CashMachine (part 7)
Let's return to the Command pattern. 1. Create a command package. It will contain all classes with relevant logic. Think about the access modifier for each class in this package. 2. Create a Command interface with a void execute() method.
undefined
40
Task
Java Collections, level 9, lesson 15
Locked
CashMachine (part 8)
It's time to whip our main method into shape. It already has a bunch of stuff that shouldn't be there. 1. Move the logic from main to DepositCommand and InfoCommand. So what's happened to main? We have a loop, in which we ask the user for an operation and then call a method on the CommandExecutor.
undefined
40
Task
Java Collections, level 9, lesson 15
Locked
CashMachine (part 9)
Today we're going to tackle ExitCommand. 1. Implement the following logic in ExitCommand: 1.1. Ask whether the user really wants to exit. Provide the following options: yes (y) or no (n). 1.2. If the user confirms, then say goodbye.
undefined
40
Task
Java Collections, level 9, lesson 15
Locked
CashMachine (part 10)
Today we'll tackle WithdrawCommand. It's the most complex operation. 1. Implement the following algorithm for WithdrawCommand: 1.1. Read the currency code (the method already exists). 1.2. Get a manipulator for the specified currency.
undefined
40
Task
Java Collections, level 9, lesson 15
Locked
CashMachine (part 11)
Congratulations! You implemented WithdrawCommand! The main functionality is finished. Next you can do some polishing and make things pretty. Let's implement one sweet feature. We can get by without it, but it will make things more beautiful. I'm talking about verification of the user's credit card.
undefined
40
Task
Java Collections, level 9, lesson 15
Locked
CashMachine (part 12)
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.
undefined
40
Task
Java Collections, level 9, lesson 15
Locked
CashMachine (part 13)
You've already figured out ResourceBundle! Cool! Now we can add localization, i.e. support for multiple languages. 1. In DepositCommand, ExitCommand, and InfoCommand, add a private ResourceBundle res field and initialize it with the appropriate resource.
undefined
40
Task
Java Collections, level 9, lesson 15
Locked
CashMachine (part 14)
1. In LoginCommand and WithdrawCommand, add a private ResourceBundle res field and initialize it with the appropriate resource. For LoginCommand, use login_en.properties. For WithdrawCommand, use withdraw_en.properties. 2. Use common_en.properties to replace all the strings in ConsoleHelper.
undefined
10
Task
Java Collections, level 9, lesson 15
Locked
CashMachine (part 15)
1. In CashMachine, create a constant for the path to the resources. public static final String RESOURCE_PATH; Refactor the loading of all the ResourceBundles to use RESOURCE_PATH. 2. The CashMachine class should have no initialization of ResourceBundles.