In class we talked about the bank account class on pages 178 and
179 in the text (with minor changes - see the text for the
complete class). Part of it is below:
//*****************************************************
// Account.java
//
// Represents a bank account; allows deposits,
// withdrawals, balance inquiries, etc.
//*****************************************************
public class Account
{
public static final double RATE = 0.035; // interest rate of 3.5%
___________________________________________________________; // $10 fee
private long acctNumber;
private double balance;
private String name;
//---------------------------------------------------
// Constructor -- initializes instance data
//---------------------------------------------------
public Account(String owner, long account, double initial)
{
name = owner;
acctNumber = account;
balance = initial;
}
//---------------------------------------------------
// Deposits the amount from the account and returns
// the new balance.
//---------------------------------------------------
public double deposit (double amount)
{
balance += amount;
return balance;
}
//---------------------------------------------------
// Simple withdrawal -- deducts amount from balance
// and returns the new balance.
//---------------------------------------------------
public double withdraw(double amount)
{
balance -= amount;
return balance;
}
//---------------------------------------------------
// Adds interest to the account and returns the
// new balance.
//---------------------------------------------------
public double addInterest ()
{
balance = balance + balance * RATE;
return balance;
}
//---------------------------------------------------
// Returns the current balance.
//---------------------------------------------------
public double getBalance()
{
return balance;
}
//------------------------------------------------------
// Deducts the service fee and returns the new balance.
//------------------------------------------------------
public double chargeFee()
{
// deduct the fee
____________________________________________________
// return the updated balance
____________________________________________________
}
//---------------------------------------------------
// Changes the name on the account to newName.
//---------------------------------------------------
public void setName(String newName)
{
___________________________________________________
}
//--------------------------------------------------
// Returns a string representation of the account.
//--------------------------------------------------
public String toString ()
{
return "Account number: " + acctNumber + "\nOwner: "
+ name + "\nCurrent balance: " + balance;
}
}
- Add a statement that declares a constant for a service fee of
$10. Add this on the blank line after the declaration of the constant
RATE. Choose the name of the constant using Java naming conventions.
- Fill in the code for method chargeFee,
which should deduct a service fee of $10 (use the constant!) from the account,
and then return the balance.
- In the last space, fill in the body for method setName
that takes a string as a parameter
and changes the name on the account to be that string.