|
|
#1 | |
|
Registered User
Join Date: Mar 2012
Posts: 1
|
.
|
|
|
|
|
|
|
#2 | |
|
Mahna Mahna
Join Date: Jul 2006
Location: Madison, Wi
Posts: 6,123
|
Part A
For starters, get rid of the first name, last name, and id instance variables in the Account class. Create an instance variable of type person and add a setter method to the Account class: Code:
class Account {
private Person person
private BigDecimal accountBalance;
public function setPerson(Person person) {
this.person = person;
}
}
The Account class needs an accountBalance instance variable. When dealing with money in Java it's best to use BigDecimal (import java.math.BigDecimal). Google it. You're also going to want to learn how to use BigDecimal.compareTo for the withdraw method. Methods: Withdraw(amount): use the BigDecimal compareto method and check if the amount argument is > the account balance. If amount > balance print message else accountBalance = accountBalance - amount Deposit(amount): add amount to accountBalance public String inquiry(): return this.accountBalance.toString For your toString method I would use StringBuilder. Again, if you don't know what that is Google it. Pull the account name and id from the person instance variable and concatenate with the current balance to create a string like the one shown in the instructions.
__________________
|
|
|
|
|
![]() |
| Thread Tools | |
|
|