Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package accounts;
- import client.*;
- class AccountCannotBeCreatedException extends Exception {
- public AccountCannotBeCreatedException(String message) {
- super(message);
- }
- }
- public abstract class AccountBuilder {
- protected Account account;
- public AccountBuilder setClient(Client client) {
- account.client = client;
- return this;
- }
- public AccountBuilder setBalance(double balance) {
- account.balance = balance;
- return this;
- }
- public AccountBuilder setCommission(double commission) {
- account.commission = commission;
- return this;
- }
- public AccountBuilder setLowerLimit(double lowerLimit) {
- account.lowerLimit = lowerLimit;
- return this;
- }
- public AccountBuilder setDaysLeft(int daysLeft) {
- account.daysLeft = daysLeft;
- return this;
- }
- public boolean isCorrect() {
- return account.isClientCorrect() &&
- account.isBalanceCorrect() &&
- account.isCommissionCorrect() &&
- account.isLowerLimitCorrect() &&
- account.areDaysLeftCorrect();
- }
- public Account build() throws AccountCannotBeCreatedException {
- if (isCorrect()) {
- return account;
- }
- throw new AccountCannotBeCreatedException("Account cannot be created");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement