Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-15-2007, 04:32 PM
Member
 
Join Date: Nov 2007
Posts: 37
Rep Power: 0
Shaolin is on a distinguished road
Default Adding numbers in array
Hi Guys,

How can I workout the sum of money from an array:

accs[0] = new Account( "Name here2", 121, 510 ) ;
accs[1] = new Account( "Name here", 12, 50 ) ;

I want to add the last 2 numbers for both items together to workout the total.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-15-2007, 06:30 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
Rep Power: 0
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
Default
Since the array is made up of Account objects, you will need to access the data through methods in that class. Something like getBalance, getTotal..... After you have that method, it's pretty straightforward.

Code:
//assuming that the getBalance method returns an int
int total = accs[0].getBalance() + accs[1].getBalance();
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prime numbers gapper New To Java 3 02-07-2008 10:09 AM
Adding numbers in a 2 dimensional array j0shizabeast New To Java 2 11-27-2007 04:31 AM
generating random numbers in a 5x5 array. acidacid New To Java 3 08-14-2007 03:44 AM
how to swap 2 numbers mary Advanced Java 1 08-02-2007 05:32 PM
Adding graphics to array romina Java 2D 1 08-01-2007 01:45 AM


All times are GMT +2. The time now is 03:54 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org