Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. package accounts;
  2.  
  3. import client.*;
  4.  
  5. class AccountCannotBeCreatedException extends Exception {
  6.     public AccountCannotBeCreatedException(String message) {
  7.         super(message);
  8.     }
  9. }
  10.  
  11. public abstract class AccountBuilder {
  12.  
  13.     protected Account account;
  14.  
  15.     public AccountBuilder setClient(Client client) {
  16.         account.client = client;
  17.         return this;
  18.     }
  19.  
  20.     public AccountBuilder setBalance(double balance) {
  21.         account.balance = balance;
  22.         return this;
  23.     }
  24.  
  25.     public AccountBuilder setCommission(double commission) {
  26.         account.commission = commission;
  27.         return this;
  28.     }
  29.  
  30.     public AccountBuilder setLowerLimit(double lowerLimit) {
  31.         account.lowerLimit = lowerLimit;
  32.         return this;
  33.     }
  34.  
  35.     public AccountBuilder setDaysLeft(int daysLeft) {
  36.         account.daysLeft = daysLeft;
  37.         return this;
  38.     }
  39.  
  40.     public boolean isCorrect() {
  41.         return  account.isClientCorrect() &&
  42.                 account.isBalanceCorrect() &&
  43.                 account.isCommissionCorrect() &&
  44.                 account.isLowerLimitCorrect() &&
  45.                 account.areDaysLeftCorrect();
  46.     }
  47.  
  48.     public Account build() throws AccountCannotBeCreatedException {
  49.             if (isCorrect()) {
  50.                 return account;
  51.             }
  52.         throw new AccountCannotBeCreatedException("Account cannot be created");
  53.     }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement