From 7a8e4c03711467e5d90064006e703f731723e3a7 Mon Sep 17 00:00:00 2001 From: serraucrr <133245442+serraucrr@users.noreply.github.com> Date: Sat, 31 May 2025 15:17:19 +0300 Subject: [PATCH] Create Create Exceptions in BankAccount.java "Certain parts of the code lacked exception handling and did not throw exceptions when necessary. The appropriate 'throws Exception' statements have been added where required." --- Create Exceptions in BankAccount.java | 63 +++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Create Exceptions in BankAccount.java diff --git a/Create Exceptions in BankAccount.java b/Create Exceptions in BankAccount.java new file mode 100644 index 0000000..7a3eebd --- /dev/null +++ b/Create Exceptions in BankAccount.java @@ -0,0 +1,63 @@ +package Bank;Add commentMore actionsAdd commentMore actions +import java.io.Serializable; + +import Exceptions.InvalidAmount; +import Exceptions.MaxBalance; +import Exceptions.MaxWithdraw; + +public class BankAccount implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + private String name; + private double balance; + protected double min_balance; + String acc_num; + //String type; + + + public BankAccount(String name, double balance, double min_balance) throws Exception { + if (balance < min_balance) { + throw new Exception("Initial balance cannot be less than the minimum required balance: " + min_balance); + } + this.name = name; + this.balance = balance; + this.min_balance = min_balance; + this.acc_num = 10000 + (int) (Math.random() * 89999) + ""; +} + + + public void deposit(double amount) throws InvalidAmount + { + if (amount <= 0){ + throw new InvalidAmount("Deposit amount must be greater than zero."); + } + balance+=amount; + } + + public void withdraw(double amount) throws MaxWithdraw, MaxBalance + { + if((balance-amount)>=min_balance && amount