Skip to content

Commit 8e82abd

Browse files
author
AmiyahJo
committed
chore: spotless apply + adds java documentation
1 parent 95bf7a1 commit 8e82abd

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6+
/** Records and prints transaction logs. */
67
public class AuditLog {
78
private final List<String> logEntries;
89

10+
/** Creates a new, empty audit log. */
911
public AuditLog() {
1012
logEntries = new ArrayList<>();
1113
}
1214

15+
/**
16+
* Adds a transaction entry to the log and prints it.
17+
*
18+
* @param accountNumber The account number involved.
19+
* @param message A message describing the transaction.
20+
* @param amount The amount of money in the transaction.
21+
* @param type The type of transaction (e.g., Deposit, Withdrawal).
22+
*/
1323
public void logTransaction(String accountNumber, String message, double amount, String type) {
1424
String logEntry =
1525
String.format(
@@ -19,6 +29,11 @@ public void logTransaction(String accountNumber, String message, double amount,
1929
System.out.println(logEntry);
2030
}
2131

32+
/**
33+
* Returns all the transaction logs.
34+
*
35+
* @return A list of all log entries.
36+
*/
2237
public List<String> getLogEntries() {
2338
return logEntries;
2439
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ public class BankAtm {
1414
private final AuditLog auditLog = new AuditLog();
1515

1616
/**
17-
* Adds a checking account to the bank.
17+
* Adds a checking account to the bank. If the account is a BusinessCheckingAccount, it ensures
18+
* that at least one of the account owners is a business.
1819
*
1920
* @param account The account to add.
21+
* @throws IllegalArgumentException if the account is a BusinessCheckingAccount and none of its
22+
* owners are business.
2023
*/
2124
public void addAccount(CheckingAccount account) {
2225
if (account instanceof BusinessCheckingAccount) {

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
package com.codedifferently.lesson17.bank;
22

3+
/** Represents a Money Order transaction. */
34
public class MoneyOrder {
45
private final CheckingAccount sourceAccount;
56
private final double amount;
67
private AuditLog auditLog;
78

9+
/**
10+
* Creates a new money order transaction by withdrawing the specified amount from the source
11+
* account. The transaction is logged for auditing purposes.
12+
*
13+
* @param sourceAccount The account from which funds will be withdrawn.
14+
* @param amount The amount to withdraw and transfer in the money order.
15+
* @param auditLog The audit log used to record the transaction details.
16+
*/
817
public MoneyOrder(CheckingAccount sourceAccount, double amount, AuditLog auditLog) {
918
this.sourceAccount = sourceAccount;
1019
this.amount = amount;
@@ -16,10 +25,20 @@ public MoneyOrder(CheckingAccount sourceAccount, double amount, AuditLog auditLo
1625
sourceAccount.getAccountNumber(), "MoneyOrder created", -amount, "MoneyOrder");
1726
}
1827

28+
/**
29+
* Gets the source account from which the money was withdrawn.
30+
*
31+
* @return The source checking account.
32+
*/
1933
public CheckingAccount getSourceAccount() {
2034
return sourceAccount;
2135
}
2236

37+
/**
38+
* Gets the amount of money involved in the Money Order transaction.
39+
*
40+
* @return The amount of the money order.
41+
*/
2342
public double getAmount() {
2443
return amount;
2544
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,47 @@
33
import com.codedifferently.lesson17.bank.exceptions.CheckNotAllowedException;
44
import java.util.Set;
55

6+
/** Represents a savings account. */
67
public class SavingsAccount extends CheckingAccount {
8+
9+
/**
10+
* Creates a new savings account.
11+
*
12+
* @param accountNumber The account number.
13+
* @param owners The owners of the account.
14+
* @param initialBalance The initial balance of the account. If it's negative, it will be set to
15+
* zero.
16+
*/
717
public SavingsAccount(String accountNumber, Set<Customer> owners, double initialBalance) {
818
super(accountNumber, owners, Math.max(initialBalance, 0));
919
}
1020

21+
/**
22+
* Deposits funds into the savings account.
23+
*
24+
* @param amount The amount to deposit.
25+
*/
1126
@Override
1227
public void deposit(double amount) {
1328
super.deposit(amount);
1429
}
1530

31+
/**
32+
* Withdraws funds from the savings account.
33+
*
34+
* @param amount The amount to withdraw.
35+
*/
1636
@Override
1737
public void withdraw(double amount) {
1838
super.withdraw(amount);
1939
}
2040

41+
/**
42+
* Throws an exception because savings accounts cannot write checks.
43+
*
44+
* @param amount The amount to write a check for.
45+
* @throws CheckNotAllowedException if attempting to write a check.
46+
*/
2147
public void writeCheck(double amount) {
2248
throw new CheckNotAllowedException("Savings account cannot write checks");
2349
}

0 commit comments

Comments
 (0)