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
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/json-20210307.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1743151987451</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"java.project.referencedLibraries": [
"lib/json-20210307.jar"
]
}
153 changes: 153 additions & 0 deletions Bank
Original file line number Diff line number Diff line change
@@ -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<String> display()
{
DefaultListModel<String> list=new DefaultListModel<String>();
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;
}

}
153 changes: 153 additions & 0 deletions Bank Class
Original file line number Diff line number Diff line change
@@ -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<String> display()
{
DefaultListModel<String> list=new DefaultListModel<String>();
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;
}

}
Loading