/**
   The BankAccount class simulates a bank account.
	@author Gaddis
	@version V2 - updated by N. Harris - Nov 1, 2009
*/

public class BankAccount
{
   private double balance;      // Account balance

   /**
      This constructor sets the starting balance
      at 0.0.
   */

   public BankAccount()
   {
      balance = 0.0;
   }
   
   /**
      This overloaded constructor sets the starting balance
      to the value passed as an argument.
      @param startBalance The starting balance.
   */

   public BankAccount(double startBalance)
   {
      balance = startBalance;
   }

   /**
      This constructor sets the starting balance
      to the value in the String argument.
      @param str The starting balance, as a String.
   */

   public BankAccount(String str)
   {
      balance = Double.parseDouble(str);
   }

   /**
      The deposit method makes a deposit into
      the account.
      @param amount The amount to add to the
                    balance field.
   */

   public void deposit(double amount)
   {
      balance = balance + amount;
   }

   /**
      The deposit method makes a deposit into
      the account.
      @param str The amount to add to the
                 balance field, as a String.
   */

   public void deposit(String str)
   {
      balance = balance + Double.parseDouble(str);
   }

   /**
      The withdraw method withdraws an amount
      from the account.
      @param amount The amount to subtract from
                    the balance field.
		@return amount withdrawn - will be zero if 
		        a withdrawal cannot take place
   */

   public double withdraw(double amount)
 	{
		if (balance >= amount)  
		{
			balance = balance - amount;
		}
		else
		{
			amount = 0;
		}			
		
		return amount;
   }

   /**
      The withdraw method withdraws an amount
      from the account.
      @param str The amount to subtract from
                 the balance field, as a String.
		@return The amount withdrawn, 0 if cannot make 
		        withdrawal
   */
   public double withdraw(String str)
   {
		double amount;
		amount = Double.parseDouble(str);
		amount = withdraw(amount);
		return amount;
	}
		
	/**
   The setBalance method sets the account balance.
   @param b The value to store in the balance field.
   */

   public void setBalance(double b)
   {
      balance = b;
   }

   /**
      The setBalance method sets the account balance.
      @param str The value, as a String, to store in
                 the balance field.
   */

   public void setBalance(String str)
   {
      balance = Double.parseDouble(str);
   }
   
   /**

      The getBalance method returns the
      account balance.
      @return The value in the balance field.
   */

   public double getBalance()
   {
      return balance;
   }
	
	/** 
		The toString method returns a String
		representing this account balance
	*/
	public String toString()
	{
		return String.format("An account with a balance of $%.2f", 
			balance);
	}
}
