Guest User

Untitled

a guest
Apr 7th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. package bg.jwd.webbanking;
  2.  
  3. import java.util.HashMap;
  4.  
  5. import org.springframework.stereotype.Service;
  6.  
  7. @Service
  8. public class WebBankingService implements WebBanking {
  9.     private static HashMap<String, Double> clients = new HashMap<String, Double>();
  10.  
  11.     @Override
  12.     public boolean withdraw(String client, double amount) {
  13.         if (client == null) {
  14.             return false;
  15.         }
  16.         if (!clients.containsKey(client)) {
  17.             return false;
  18.         }
  19.  
  20.         Double currentAmount = clients.get(client);
  21.         if (amount > currentAmount) {
  22.             return false;
  23.         }
  24.  
  25.         Double newAmount = currentAmount - amount;
  26.         clients.put(client, newAmount);
  27.         return true;
  28.     }
  29.  
  30.     @Override
  31.     public boolean deposit(String client, double amount) {
  32.         if (client == null || amount <= 0) {
  33.             return false;
  34.         }
  35.         if (!clients.containsKey(client)) {
  36.             clients.put(client, 0.0);
  37.         }
  38.         clients.put(client, amount);
  39.         return true;
  40.     }
  41.  
  42. }
Add Comment
Please, Sign In to add comment