A good answer might be:
| ||||||||||||
Implementing the ConstructorYou might have thought of equally valid names for the variables. The account number should be a String, because it is not a numeric quantity that is expected to take part in arithmetic operations. Sometimes account numbers contain dashes or other non-digit characters. The balance will be kept in terms of pennies, so should be an int . So far, the CheckingAccount class looks like this:
Remember that we are defining a class,
so it does not make sense to assign initial values to the variables
in the data declarations section
(since each individual object will have different values.)
Next, consider the constructor.
The constructor will have the same name as the class,
so it will look something like this:
Recall from the requirements what we want the constructor to do:
it should
create a new
checking account and initialize it with the account number, the
account holder's name, and starting balance.
The constructor does not need any statements that actually create an object out of main storage (this happens automatically.) It does need to initialize the object's data after it has been created. When a CheckingAccount constructor is used the call will provide actual parameters, such as in the following:
This statement creates a new CheckingAccount object by calling the
constructor.
The constructor will initialize the object's accountNumber to "123",
its accountHolder to "Bob", and its balance to
100.
| ||||||||||||
QUESTION 6:Fill in the parameter list for the constructor. You will have to think of names for the parameters, and will have to include the type of each parameter.
Click Here after you have answered the question
|