This repository has been archived on 2021-06-15. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
CS1-projects/lab05/src/BankAccount.java
2021-03-26 22:45:38 -05:00

65 lines
No EOL
1.5 KiB
Java

/**
* 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;
}
}