Advertisement
Guest User

Debug Assignment (1/1)

a guest
Jul 29th, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. import java.text.*; // Imported for DecimalFormat class
  2. public class SimpleAccount
  3. {
  4.    private double balance; // Account balance
  5.  private String owner;  // Name of account holder, also used as id  
  6. private int numDeposits=0,numWithdrawals=0;
  7.    public SimpleAccount(String name)
  8.    {
  9.       balance = 0.0;
  10.   owner = name;
  11.    }
  12.    public SimpleAccount(String name, double startBalance)
  13.    {
  14.       balance = startBalance;
  15.   owner = name;
  16.    }
  17.  
  18.    public void deposit(double amount)
  19.    {
  20.       balance += amount;
  21.    }
  22.  
  23.    public void withdraw(double amount)
  24.    {
  25.       if(amount <= balance)
  26.   {    
  27.     balance -= amount;
  28.   }
  29.   else
  30.   {
  31.     System.out.println("Overdraw warning");
  32.   }
  33.    }
  34.  
  35.    public double getBalance()
  36.    {
  37.       return balance;
  38.    }
  39.  
  40.  public String getOwner()
  41.    {
  42.       return owner;
  43.    }
  44. public void incrementDeposits()
  45.    {
  46.       numDeposits++;
  47.    }
  48. public void incrementWithdrawals()
  49.    {
  50.       numWithdrawals++;
  51.    }
  52. public String toString()
  53.    {
  54.       DecimalFormat formatter = new DecimalFormat("$#0.00");    
  55.   return owner + ": " + formatter.format(balance)+ "\nDeposits Count " + numDeposits+"\nWithDrawals Count" +
  56.     numWithdrawals+"\nFees :$" + (numWithdrawals * 0.2);
  57.    }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement