In class we talked about the bank account class described below:
//*****************************************************
// Account.java
//
// A class representing a bank account; allows deposits,
// withdrawals, balance inquiries, etc.
//*****************************************************
public class Account
{
private double balance;
private String name;
private long acctNum;
//---------------------------------------------------
// Constructor -- initializes instance data
//---------------------------------------------------
public Account(double initBal, String owner, long number)
{
balance = initBal;
name = owner;
acctNum = number;
}
//---------------------------------------------------
// Simple withdrawal -- deducts amount from balance
// If balance doesn't cover withdrawal, prints message
// and does not change balance.
//---------------------------------------------------
public void withdraw(double amount)
{
if (balance >= amount)
balance -= amount;
else
System.out.println("Insufficient funds");
}
//---------------------------------------------------
// Simple deposit -- adds amount to balance.
//---------------------------------------------------
public void deposit(double amount)
{
balance += amount;
}
//---------------------------------------------------
// Returns balance.
//---------------------------------------------------
public double getBalance()
{
return balance;
}
//---------------------------------------------------
// Prints name, account number, and balance
//---------------------------------------------------
public void printSummary()
{
//print name
_____________________________
//print acct number
_____________________________
//print balance
_____________________________
}
//---------------------------------------------------
// Deducts $10 service fee if balance is under $1000
//---------------------------------------------------
public void chargeFee()
{
}
//---------------------------------------------------
// Changes the name on the account to newName.
//---------------------------------------------------
public void changeName(String newName)
{
}
}
- Fill in the code for method printSummary, which should
print the name, account number, and balance for the account.
- Fill in the code for method chargeFee,
which should deduct a service
fee from the account. If the balance is $1000 or more, no fee should be
charged, but if it is less than $1000, $10 should be deducted from the
balance.
- Modify chargeFee so that instead of returning
no value (type void), it returns the new balance.
Note that you will have to make
changes in two places -- add a return statement and change the return type.
- In the last space, fill in the body for method changeName
that takes a string
as a parameter
and changes the name on the account to be that string.