Untitled

 avatar
unknown
plain_text
2 years ago
2.4 kB
5
Indexable
import java.text.NumberFormat;

public class Account
{
   private static final double RATE = 0.035;  // interest rate of 3.5%

   private long acctNumber;
   private double balance;
   private String name;

   //-----------------------------------------------------------------
   //  Sets up the account by defining its owner, account number,
   //  and initial balance.
   //-----------------------------------------------------------------
   public Account (String owner, long accountNum, double initial)
   {
      this.name = owner;
      this.acctNumber = accountNum;
      this.balance = initial;
   } 

   //-----------------------------------------------------------------
   //  Deposits the specified amount into the account. Returns the
   //  new balance.
   //-----------------------------------------------------------------
   public double deposit (double amount)
   {
      this.balance = this.balance + amount;

      return this.balance;
   } 

   //-----------------------------------------------------------------
   //  Withdraws the specified amount from the account and applies
   //  the fee. Returns the new balance.
   //-----------------------------------------------------------------
   public double withdraw (double amount, double fee)
   {
      this.balance = this.balance - amount - fee;

      return this.balance;
   } 

   //-----------------------------------------------------------------
   //  Adds interest to the account and returns the new balance.
   //-----------------------------------------------------------------
   public double addInterest ()
   {
      this.balance += (this.balance * RATE);

      return this.balance;
   }

   //-----------------------------------------------------------------
   //  Returns the current balance of the account.
   //-----------------------------------------------------------------
   public double getBalance ()
   {
      return this.balance;
   }

   //-----------------------------------------------------------------
   //  Returns a one-line description of the account as a string.
   //-----------------------------------------------------------------
   public String toString ()
   {
      NumberFormat fmt = NumberFormat.getCurrencyInstance();

      return (this.acctNumber + "\t" + this.name + "\t" + fmt.format(this.balance));
   } 

} 
Editor is loading...