"హాయ్, అమిగో!"
"హలో, కెప్టెన్ ఉడుతలు, సార్."
"నువ్వు మంచి స్టూడెంట్వి. వెల్ డన్, సైనికుడు!"
"ఈ రోజు మీకు కొత్త రహస్య మిషన్ ఉంది: మాస్టర్ ఫైనాన్స్."
"హుర్రే!!! నేను డబ్బును దేనికి ఖర్చు చేస్తానో నాకు ముందే తెలుసు!!!"
“ఇంకా విశ్రాంతి తీసుకోకు, సైనికా! ఫైనాన్స్లో పట్టు సాధించడం అంటే కొత్త రహస్య ATM ప్రోగ్రామ్ రాయడం.
"సీక్రెట్ ఏజెంట్ IntelliJ IDEAని చూడండి. మీరు అక్కడ అన్ని సూచనలను స్వీకరిస్తారు."
"ఇది జరుగుతుంది, కెప్టెన్!"
10
టాస్క్
Java Collections, స్థాయి, పాఠం
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.
10
టాస్క్
Java Collections, స్థాయి, పాఠం
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.
20
టాస్క్
Java Collections, స్థాయి, పాఠం
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.
40
టాస్క్
Java Collections, స్థాయి, పాఠం
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.
20
టాస్క్
Java Collections, స్థాయి, పాఠం
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.
20
టాస్క్
Java Collections, స్థాయి, పాఠం
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.
20
టాస్క్
Java Collections, స్థాయి, పాఠం
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.
40
టాస్క్
Java Collections, స్థాయి, పాఠం
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.
40
టాస్క్
Java Collections, స్థాయి, పాఠం
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.
40
టాస్క్
Java Collections, స్థాయి, పాఠం
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.
40
టాస్క్
Java Collections, స్థాయి, పాఠం
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.
40
టాస్క్
Java Collections, స్థాయి, పాఠం
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.
40
టాస్క్
Java Collections, స్థాయి, పాఠం
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.
40
టాస్క్
Java Collections, స్థాయి, పాఠం
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.
10
టాస్క్
Java Collections, స్థాయి, పాఠం
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.