nV News Forums

 
 

nV News Forums (http://www.nvnews.net/vbulletin/index.php)
-   General Software (http://www.nvnews.net/vbulletin/forumdisplay.php?f=10)
-   -   Help java project (eclipse) (http://www.nvnews.net/vbulletin/showthread.php?t=175693)

Tyler1991 03-06-12 07:32 PM

Help java project (eclipse)
 
.

jcrox 03-06-12 08:36 PM

Re: Help java project (eclipse)
 
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;
}

}

Now the attributes that belong to a person stay in the person class and you can still access them anywhere in the Account class.

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.


All times are GMT -5. The time now is 02:20 PM.

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 1998 - 2014, nV News.