diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 52f0fec..0e68541 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,7 +1,7 @@ name: Test School Java on: - pull_request_target:: + pull_request_target: types: [opened, synchronize, reopened] branches: ["main", "master"] diff --git a/pom.xml b/pom.xml index a51d399..64325a3 100644 --- a/pom.xml +++ b/pom.xml @@ -12,8 +12,8 @@ CLI-based Java banking application - 17 - 17 + 11 + 11 diff --git a/src/main/java/cse/school/codejam/BankAccount.java b/src/main/java/cse/school/codejam/BankAccount.java index 5161d71..c61e72e 100644 --- a/src/main/java/cse/school/codejam/BankAccount.java +++ b/src/main/java/cse/school/codejam/BankAccount.java @@ -19,15 +19,21 @@ 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() { @@ -35,7 +41,7 @@ public String getAccountDetails() { } public String getAccountNumber() { - return "accountNumber"; + return accountNumber; } public void setAccountHolderName(String name) { diff --git a/src/main/java/cse/school/codejam/InputUtil.java b/src/main/java/cse/school/codejam/InputUtil.java index 0bd04c0..e6e98d9 100644 --- a/src/main/java/cse/school/codejam/InputUtil.java +++ b/src/main/java/cse/school/codejam/InputUtil.java @@ -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) { @@ -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."); diff --git a/src/main/java/cse/school/codejam/Transaction.java b/src/main/java/cse/school/codejam/Transaction.java index 6836d96..6d81cc2 100644 --- a/src/main/java/cse/school/codejam/Transaction.java +++ b/src/main/java/cse/school/codejam/Transaction.java @@ -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; }