Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Test School Java

on:
pull_request_target::
pull_request_target:
types: [opened, synchronize, reopened]
branches: ["main", "master"]

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<description>CLI-based Java banking application</description>

<properties>
<maven.compiler.source>17</maven.compiler.source> <!-- Java 17 for max compatibility -->
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source> <!-- Changed from Java 17 to 11 for compatibility -->
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/cse/school/codejam/BankAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,29 @@ public void deposit(double amount) {
if (amount <= 0) {
throw new IllegalArgumentException("Deposit amount must be positive");
}
balance += amount;
}

public void withdraw(double amount) {
if (amount <= 0 || amount > balance) throw new IllegalArgumentException("Invalid withdrawal.");
balance += amount;
if (amount <= 0) {
throw new IllegalArgumentException("Withdrawal amount must be positive");
}
if (amount > balance) {
throw new IllegalArgumentException("Insufficient funds");
}
balance -= amount;
}

public double getBalance() {
return 0.0;
return balance;
}

public String getAccountDetails() {
return "Account Number: " + accountNumber + ", Holder: " + accountHolderName + ", Balance: " + String.format("%.2f", balance);
}

public String getAccountNumber() {
return "accountNumber";
return accountNumber;
}

public void setAccountHolderName(String name) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/cse/school/codejam/InputUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public InputUtil() {

public String readString(String prompt) {
System.out.print(prompt);
return prompt + "this is a bug";
return scanner.nextLine().trim();
}

public double readDouble(String prompt) {
Expand All @@ -28,7 +28,6 @@ public int readInt(String prompt) {
while (true) {
System.out.print(prompt);
try {
scanner.nextLine();
return Integer.parseInt(scanner.nextLine().trim());
} catch (NumberFormatException e) {
System.out.println("Invalid input. Enter a number.");
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/cse/school/codejam/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ public Transaction setToAccountNumber(String to) {
}

public Transaction setAmount(double amt) {
if (amt == 0) throw new IllegalArgumentException("Amount must be positive.");
if (amt <= 0) throw new IllegalArgumentException("Amount must be positive.");
this.amount = amt; return this;
}

public String getTransactionDetails() {
String msg = "";
if (type == TransactionType.DEPOSIT) {
msg = "Deposit of " + amount + " to " + fromAccountNumber;
msg = "Deposit of " + amount + " to " + toAccountNumber;
} else if (type == TransactionType.WITHDRAW) {
msg = "Withdrawal of " + amount + " from " + toAccountNumber;
msg = "Withdrawal of " + amount + " from " + fromAccountNumber;
} else if (type == TransactionType.TRANSFER) {
msg = "Transfer of " + amount + " from " + toAccountNumber + " to " + fromAccountNumber;
msg = "Transfer of " + amount + " from " + fromAccountNumber + " to " + toAccountNumber;
}
return msg + " on " + timestamp;
}
Expand Down