Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bg.jwd.webbanking;
- import java.util.HashMap;
- import org.springframework.stereotype.Service;
- @Service
- public class WebBankingService implements WebBanking {
- private static HashMap<String, Double> clients = new HashMap<String, Double>();
- @Override
- public boolean withdraw(String client, double amount) {
- if (client == null) {
- return false;
- }
- if (!clients.containsKey(client)) {
- return false;
- }
- Double currentAmount = clients.get(client);
- if (amount > currentAmount) {
- return false;
- }
- Double newAmount = currentAmount - amount;
- clients.put(client, newAmount);
- return true;
- }
- @Override
- public boolean deposit(String client, double amount) {
- if (client == null || amount <= 0) {
- return false;
- }
- if (!clients.containsKey(client)) {
- clients.put(client, 0.0);
- }
- clients.put(client, amount);
- return true;
- }
- }
Add Comment
Please, Sign In to add comment