Skip to content
Open
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
63 changes: 63 additions & 0 deletions Create Exceptions in BankAccount.java
Original file line number Diff line number Diff line change
@@ -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<balance)
{
balance-=amount;

}

else
{
throw new MaxBalance("Insufficient Balance");
}
}

public double getbalance()
{
return balance;
}

@Override
public String toString() {
return "Name: " + name + ", Id: " + acc_num + ", Balance: " + balance +"Type:"+this.getClass();
}
}