diff --git a/.classpath b/.classpath index 0cbf9cd..485143e 100644 --- a/.classpath +++ b/.classpath @@ -2,5 +2,6 @@ + diff --git a/.project b/.project index 9c3e68a..dfc0bbe 100644 --- a/.project +++ b/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1743151987451 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..edeafa4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "java.project.referencedLibraries": [ + "lib/json-20210307.jar" + ] +} diff --git a/Bank b/Bank new file mode 100644 index 0000000..08f0dbc --- /dev/null +++ b/Bank @@ -0,0 +1,153 @@ +package Bank; +import java.io.Serializable; +import javax.swing.DefaultListModel; +import Exceptions.AccNotFound; +import Exceptions.InvalidAmount; +import Exceptions.MaxBalance; +import Exceptions.MaxWithdraw; + +public class Bank implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + private BankAccount[] accounts= new BankAccount[100]; + public int addAccount(BankAccount acc) + { + int i=0; + for(i=0;i<100;i++) + { + if(getAccounts()[i]==null) + { + break; + } + } + getAccounts()[i]=acc; + return i; + } + + public int addAccount(String name, double balance, double maxWithLimit ) throws Exception + { + SavingsAccount acc=new SavingsAccount(name, balance, maxWithLimit); + return this.addAccount(acc); + } + + public int addAccount(String name, double balance, String tradeLicense) throws Exception + { + CurrentAccount acc = new CurrentAccount(name, balance,tradeLicense); + return this.addAccount(acc); + } + + public int addAccount(String name, String institutionName, double balance, double min_balance) throws Exception + { + StudentAccount acc= new StudentAccount(name,balance,institutionName); + return this.addAccount(acc); + } + + public BankAccount findAccount(String aacountNum) + { + int i; + for(i=0;i<100;i++) + { + if(getAccounts()[i]==null) + { + break; + } + if(getAccounts()[i].acc_num.equals(aacountNum)) + { + return getAccounts()[i]; + } + + } + return null; + } + + public void deposit(String aacountNum, double amt) throws InvalidAmount,AccNotFound + + { + if(amt<0) + { + throw new InvalidAmount("Invalid Deposit amount"); + } + BankAccount temp=findAccount(aacountNum); + if(temp==null) + { + throw new AccNotFound("Account Not Found"); + } + if(temp!=null) + { + temp.deposit(amt); + + } + + } + + + public void withdraw(String aacountNum, double amt) throws MaxBalance,AccNotFound, MaxWithdraw, InvalidAmount + { + BankAccount temp=findAccount(aacountNum); + + if(temp==null) + { + throw new AccNotFound("Account Not Found"); + } + + if(amt<=0) + { + throw new InvalidAmount("Invalid Amount"); + } + + if(amt>temp.getbalance()) + { + throw new MaxBalance("Insufficient Balance"); + } + if(temp!=null) + { + temp.withdraw(amt); + } + } + + public DefaultListModel display() + { + DefaultListModel list=new DefaultListModel(); + int i; +// String type=null; + + for(i=0;i<100;i++) + { + if(getAccounts()[i]==null) + { + break; + } +// if(getAccounts()[i].getClass().toString().equals("class Bank.SavingsAccount")) +// { +// type="Type: Savings Account"; +// } +// +// else if(getAccounts()[i].getClass().toString().equals("class Bank.CurrentAccount")) +// { +// type="Type: Current Account"; +// } +// +// else if(getAccounts()[i].getClass().toString().equals("class Bank.StudentAccount")) +// { +// type="Type: Student Account"; +// } + + list.addElement(getAccounts()[i].toString()); + + + } + + return list; + } + + public BankAccount[] getAccounts() { + return accounts; + } + + public void setAccounts(BankAccount[] accounts) { + this.accounts = accounts; + } + +} diff --git a/Bank Class b/Bank Class new file mode 100644 index 0000000..840fee0 --- /dev/null +++ b/Bank Class @@ -0,0 +1,153 @@ +package Bank;Add commentMore actions +import java.io.Serializable; +import javax.swing.DefaultListModel; +import Exceptions.AccNotFound; +import Exceptions.InvalidAmount; +import Exceptions.MaxBalance; +import Exceptions.MaxWithdraw; + +public class Bank implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + private BankAccount[] accounts= new BankAccount[100]; + public int addAccount(BankAccount acc) + { + int i=0; + for(i=0;i<100;i++) + { + if(getAccounts()[i]==null) + { + break; + } + } + getAccounts()[i]=acc; + return i; + } + + public int addAccount(String name, double balance, double maxWithLimit ) throws Exception + { + SavingsAccount acc=new SavingsAccount(name, balance, maxWithLimit); + return this.addAccount(acc); + } + + public int addAccount(String name, double balance, String tradeLicense) throws Exception + { + CurrentAccount acc = new CurrentAccount(name, balance,tradeLicense); + return this.addAccount(acc); + } + + public int addAccount(String name, String institutionName, double balance, double min_balance) throws Exception + { + StudentAccount acc= new StudentAccount(name,balance,institutionName); + return this.addAccount(acc); + } + + public BankAccount findAccount(String aacountNum) + { + int i; + for(i=0;i<100;i++) + { + if(getAccounts()[i]==null) + { + break; + } + if(getAccounts()[i].acc_num.equals(aacountNum)) + { + return getAccounts()[i]; + } + + } + return null; + } + + public void deposit(String aacountNum, double amt) throws InvalidAmount,AccNotFound + + { + if(amt<0) + { + throw new InvalidAmount("Invalid Deposit amount"); + } + BankAccount temp=findAccount(aacountNum); + if(temp==null) + { + throw new AccNotFound("Account Not Found"); + } + if(temp!=null) + { + temp.deposit(amt); + + } + + } + + + public void withdraw(String aacountNum, double amt) throws MaxBalance,AccNotFound, MaxWithdraw, InvalidAmount + { + BankAccount temp=findAccount(aacountNum); + + if(temp==null) + { + throw new AccNotFound("Account Not Found"); + } + + if(amt<=0) + { + throw new InvalidAmount("Invalid Amount"); + } + + if(amt>temp.getbalance()) + { + throw new MaxBalance("Insufficient Balance"); + } + if(temp!=null) + { + temp.withdraw(amt); + } + } + + public DefaultListModel display() + { + DefaultListModel list=new DefaultListModel(); + int i; +// String type=null; + + for(i=0;i<100;i++) + { + if(getAccounts()[i]==null) + { + break; + } +// if(getAccounts()[i].getClass().toString().equals("class Bank.SavingsAccount")) +// { +// type="Type: Savings Account"; +// } +// +// else if(getAccounts()[i].getClass().toString().equals("class Bank.CurrentAccount")) +// { +// type="Type: Current Account"; +// } +// +// else if(getAccounts()[i].getClass().toString().equals("class Bank.StudentAccount")) +// { +// type="Type: Student Account"; +// } + + list.addElement(getAccounts()[i].toString()); + + + } + + return list; + } + + public BankAccount[] getAccounts() { + return accounts; + } + + public void setAccounts(BankAccount[] accounts) { + this.accounts = accounts; + } + +} diff --git a/BankAcoount.java b/BankAcoount.java new file mode 100644 index 0000000..5d3c2ea --- /dev/null +++ b/BankAcoount.java @@ -0,0 +1,63 @@ +package Bank; +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=min_balance && amount