Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.*; // Imported for DecimalFormat class
- public class SimpleAccount
- {
- private double balance; // Account balance
- private String owner; // Name of account holder, also used as id
- private int numDeposits=0,numWithdrawals=0;
- public SimpleAccount(String name)
- {
- balance = 0.0;
- owner = name;
- }
- public SimpleAccount(String name, double startBalance)
- {
- balance = startBalance;
- owner = name;
- }
- public void deposit(double amount)
- {
- balance += amount;
- }
- public void withdraw(double amount)
- {
- if(amount <= balance)
- {
- balance -= amount;
- }
- else
- {
- System.out.println("Overdraw warning");
- }
- }
- public double getBalance()
- {
- return balance;
- }
- public String getOwner()
- {
- return owner;
- }
- public void incrementDeposits()
- {
- numDeposits++;
- }
- public void incrementWithdrawals()
- {
- numWithdrawals++;
- }
- public String toString()
- {
- DecimalFormat formatter = new DecimalFormat("$#0.00");
- return owner + ": " + formatter.format(balance)+ "\nDeposits Count " + numDeposits+"\nWithDrawals Count" +
- numWithdrawals+"\nFees :$" + (numWithdrawals * 0.2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement