#256 ATM Implementation with a Contract
Write an ATM class according to the contract:
/**
* ATM.
* Interacts with the SDK whose contracts are described below.
* Implement a request for dispensing a specified amount in rubles.
* If the required amount cannot be dispensed, return a refusal.
* Supported denominations: 50₽, 100₽, 500₽, 1000₽, 5000₽.
*/
class ATM {
// place for code
}
/**
* The SDK interface may be changed or extended by agreement between the parties if necessary.
*/
interface Sdk {
/**
* Count the number of banknotes of a particular denomination in the ATM.
* This operation takes about 10 seconds and is noisy, so it should be called as rarely as possible.
*
* @param banknote banknote denomination
* @return number of banknotes in the ATM
*/
int countBanknotes(int banknote);
/**
* Move a specified number of banknotes of one denomination to the dispenser tray.
*
* @param banknote banknote denomination
* @param count number of banknotes
*/
void moveBanknoteToDispenser(int banknote, int count);
/**
* Open the dispenser tray.
*/
void openDispenser();
}
/**
* Example SDK implementation that can be used in tests.
* The implementation may and should be changed.
*/
class StubSdk implements Sdk {
@Override
public int countBanknotes(int banknote) {
return 0;
}
@Override
public void moveBanknoteToDispenser(int banknote, int count) {
System.out.printf("Moving banknote %s to the dispenser tray, %s banknotes%n", banknote, count);
}
@Override
public void openDispenser() {
System.out.printf("The dispenser tray is open for the user%n");
}
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor