inital commit
This commit is contained in:
commit
aa37ae1eec
55 changed files with 3927 additions and 0 deletions
65
lab05/src/BankAccount.java
Normal file
65
lab05/src/BankAccount.java
Normal file
|
@ -0,0 +1,65 @@
|
|||
|
||||
/**
|
||||
* BankAccount class that represents a real world entity Bank Account. It supports deposit, withdrawal
|
||||
* and checking balance operations.
|
||||
*
|
||||
* @author Pratap Kotala
|
||||
* @version 9/23/2014
|
||||
*/
|
||||
public class BankAccount
|
||||
{
|
||||
//instance variable balance to store the balance amount information
|
||||
private double balance;
|
||||
|
||||
/**
|
||||
* Default constructor for objects of class BankAccount which initializes balance to zero.
|
||||
*/
|
||||
public BankAccount()
|
||||
{
|
||||
// initialise instance variables
|
||||
balance = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for objects of class BankAccount which initializes balance to amount.
|
||||
*/
|
||||
public BankAccount(double amount)
|
||||
{
|
||||
balance = amount;
|
||||
}
|
||||
/**
|
||||
* getBalance() method returns the current balance
|
||||
*
|
||||
* @param no parameter
|
||||
* @return double
|
||||
*/
|
||||
public double getBalance()
|
||||
{
|
||||
return balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* deposit() method adds the amount to the current balance
|
||||
*
|
||||
* @param double amount
|
||||
* @return void
|
||||
*/
|
||||
public void deposit(double amount)
|
||||
{
|
||||
balance += amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* withdraw() method reduces the current balance by amount
|
||||
*
|
||||
* @param double amount
|
||||
* @return void
|
||||
*/
|
||||
public void withdraw(double amount)
|
||||
{
|
||||
if (amount > balance)
|
||||
throw new IllegalArgumentException("insufficient balance");
|
||||
else
|
||||
balance -= amount;
|
||||
}
|
||||
}
|
Reference in a new issue