Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import bank.Account;
- import bank.CustomerWSPOA;
- public class CustomerWSImpl extends CustomerWSPOA {
- private ArrayList<Account> accounts;
- public CustomerWSImpl(ArrayList<Account> accounts) {
- this.accounts = accounts;
- }
- @Override
- public double getBalance(int accountId) {
- double balance = 0;
- for (int i = 0; i < accounts.size(); i++) {
- if (accounts.get(i).accountId == accountId) {
- balance = accounts.get(i).balance;
- System.out.println("The balance of acount with ID "
- + accounts.get(i).accountId + " is " + balance);
- } else {
- balance = -1;
- }
- }
- return balance;
- }
- @Override
- public boolean moveAmount(int fromId, int toId, double amount) {
- boolean result = false;
- for (int i = 0; i < accounts.size(); i++) {
- for (int y = 0; y < accounts.size(); y++) {
- if ((accounts.get(i).accountId == fromId)
- && (accounts.get(y).accountId == toId)) {
- if (accounts.get(i).balance >= amount) {
- accounts.get(i).balance -= amount;
- accounts.get(y).balance += amount;
- return result = true;
- }
- if (accounts.get(i).balance < amount) {
- System.out
- .println("The are no enought money to transfer. This account has: "
- + accounts.get(i).balance);
- return result = false;
- }
- } else {
- System.out
- .println("There is some problem please contact with nearest branch.");
- result = false;
- }
- }
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement