Skip to content

Commit 704b748

Browse files
author
AmiyahJo
committed
fix: customer java isBusiness boolean included , removes for loop of hasBusinessAccount
feat: adds java documentation in businessCheckingAccount
1 parent b39c805 commit 704b748

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/BusinessCheckingAccount.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,22 @@
44
public class BusinessCheckingAccount extends CheckingAccount{
55
private final String businessName;
66

7+
/**
8+
* Creates a new business checking account.
9+
*
10+
* @param accountNumber The account number.
11+
* @param owners The owners of the account.
12+
* @param businessName The name of the business.
13+
* @param initialBalance The initial balance of the account.
14+
* @throws IllegalArgumentException if no business owner is provided.
15+
*/
716
public BusinessCheckingAccount(String accountNumber, Set<Customer> owners, String businessName, double initialBalance) {
817
super(accountNumber, owners, initialBalance);
9-
this.businessName = businessName;
10-
}
1118

12-
public String getBusinessName() {
13-
return businessName;
14-
}
19+
boolean hasBusinessOwner = owners.stream().anyMatch(Customer::isBusiness);
20+
if (!hasBusinessOwner) {
21+
throw new IllegalArgumentException("At least one owner must be a business.");
22+
}
23+
this.businessName = businessName;
24+
}
1525
}

lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/Customer.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ public class Customer {
1010
private final UUID id;
1111
private final String name;
1212
private final Set<CheckingAccount> accounts = new HashSet<>();
13+
private final boolean isBusiness;
1314

1415
/**
1516
* Creates a new customer.
1617
*
1718
* @param id The ID of the customer.
1819
* @param name The name of the customer.
1920
*/
20-
public Customer(UUID id, String name) {
21+
public Customer(UUID id, String name, boolean isBusiness) {
2122
this.id = id;
2223
this.name = name;
24+
this.isBusiness = isBusiness;
2325
}
2426

2527
/**
@@ -40,6 +42,10 @@ public String getName() {
4042
return name;
4143
}
4244

45+
public boolean isBusiness() {
46+
return isBusiness;
47+
}
48+
4349
/**
4450
* Adds a checking account to the customer.
4551
*
@@ -58,20 +64,6 @@ public Set<CheckingAccount> getAccounts() {
5864
return accounts;
5965
}
6066

61-
/**
62-
* Checks if the customer has at least one business account.
63-
*
64-
* @return true if the customer has a business account, false otherwise.
65-
*/
66-
public boolean hasBusinessAccount() {
67-
for (CheckingAccount account : accounts) {
68-
if (account instanceof BusinessCheckingAccount) {
69-
return true; // Found a business account
70-
}
71-
}
72-
return false;
73-
}
74-
7567
@Override
7668
public int hashCode() {
7769
return id.hashCode();

0 commit comments

Comments
 (0)