Java Reference
In-Depth Information
The
Account
class, shown in Listing 4.4, represents a basic bank account. It
contains instance data representing the account number, the account's current
balance, and the name of the account's owner. Note that instance data can be an
object reference variable (not just a primitive type), such as the account owner's
name, which is a reference to a
String
object. The interest rate for the account is
stored as a constant.
The constructor of the
Account
class accepts three parameters that are used to
initialize the instance data. The
deposit
and
withdraw
methods perform the basic
VideoNote
Discussion of the
Account
class.
LISTING 4.4
//********************************************************************
// Account.java Author: Lewis/Loftus
//
// Represents a bank account with basic services such as deposit
// and withdraw.
//********************************************************************
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)
Search WWH ::
Custom Search