1) Overload the constructors as follows. public Account (double initBal, String owner, long number) - initializes the...
Question:
- public Account (double initBal, String owner, long number)- initializes the balance, owner, and account number as specified
- public Account (double initBal, String owner)- initializes the balance and owner as specified; randomly generates the account number.
- public Account (String owner)- initializes the owner as specified; sets the initial balance to 0 and randomly generates the account number.
2) Overload thewithdrawmethod with one that also takes a fee and deducts that fee from the account.
3) Add a method static voidclose(Account account) to your Account class. This method should close the current account by appending CLOSED to the account name and setting the balance to 0. (The account number should remain unchanged.)
3) Add a static methodAccount join(Account acct1, Account acct2)to your Account class that creates a new account whose balance is the sum of the balances in acct1 and acct2 and closes acct1 and acct2. The new account should be returned and have a new account number. The name on the new account with be the name from acct1 and acct2 concatenated with an&in the middle.
4) Make a driver that creates account objects and test all its methods.
import java.text.NumberFormat;
public class Account
{
private 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 account, double initial)
{
name = owner;
acctNumber = account;
balance = initial;
}
//-----------------------------------------------------------------
// Deposits the specified amount into the account. Returns the
// new balance.
//-----------------------------------------------------------------
public double deposit(double amount)
{
balance = balance + amount;
return balance;
}
//-----------------------------------------------------------------
// Withdraws the specified amount from the account. Returns the new balance.
//-----------------------------------------------------------------
public double withdraw(double amount)
{
balance = balance - amount;
return balance;
}
//-----------------------------------------------------------------
// Adds interest to the account and returns the new balance.
//-----------------------------------------------------------------
public double addInterest()
{
balance += (balance * RATE);
return balance;
}
//-----------------------------------------------------------------
// Returns the current balance of the account.
//-----------------------------------------------------------------
public double getBalance()
{
return balance;
}
//-----------------------------------------------------------------
// Returns a one-line description of the account as a string.
//-----------------------------------------------------------------
public String toString()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();
return (acctNumber + \"\\t\" + name + \"\\t\" + fmt.format(balance));
}
}