Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-30-2008, 05:30 AM
Member
 
Join Date: Apr 2008
Posts: 3
rattle is on a distinguished road
Calling a method for all instances of an object
Hi
Code:
import java.lang.*; import java.util.*; public class BankManagement{ public static void main(String[] args) { //vars, objects // construct instances of BankAccount and pass initial account information // account-no First Last Type balance credit BankAccount acc01 = new BankAccount(3856296735L,"Jenny","Popdeck","savings",4820.88,-50); BankAccount acc02 = new BankAccount(3478957793L,"Alex","Fryhall","credit",11899,-10000); BankAccount acc03 = new BankAccount(3709409798L,"Joey","Boilcraft","check",333.60,0); } }
given the above and my BankAccount class has a method getDetails() which prints a formatted list of vars for the account object.

Please suggest a way of running the method for all instances of the BankAccount object which would essentially be

Code:
acc01.getDetails();acc02.getDetails();acc03.getDetails();
but automatic


thanks in advance for your considerate help
mick

Last edited by rattle : 04-30-2008 at 05:34 AM. Reason: typos typos typos!!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-30-2008, 05:37 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
use a for loop

for(int i = 0; i < myArray.length; i++)
{
myArray[i].getDetails;
}
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-30-2008, 05:49 AM
Member
 
Join Date: Apr 2008
Posts: 3
rattle is on a distinguished road
the bit i don't get is how to get all the instance names into an array in one statement.

Last edited by rattle : 04-30-2008 at 05:51 AM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-30-2008, 07:21 AM
Member
 
Join Date: Apr 2008
Posts: 3
rattle is on a distinguished road
and even when i wack the instance names into an array manually, it spits out"
Code:
import java.lang.*; import java.util.*; public class BankManagement{ public static void main(String[] args) { //vars, objects String temp=""; // construct instances of BankAccount and pass initial account information // account-no First Last Type balance credit BankAccount acc01 = new BankAccount(3856296735L,"Jenny","Popdeck","savings",4820.88,-50); BankAccount acc02 = new BankAccount(3478957793L,"Alex","Fryhall","credit",11899,-10000); BankAccount acc03 = new BankAccount(3709409798L,"Joey","Boilcraft","check",333.60,0); String[] accArray={"acc01", "acc02", "acc03"}; for(int i = 0; i < accArray.length; i++){ accArray[i].getAccountDetails(); } } }
Code:
C:\Documents and Settings\User\My Documents\Java\BankManagement.java:20: cannot find symbol symbol : method getAccountDetails() location: class java.lang.String accArray[i].getAccountDetails(); ^ 1 error
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-30-2008, 03:10 PM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 183
danielstoner is on a distinguished road
Try this:

Code:
BankAccount [] accArray={acc01, acc02, acc03};
__________________
Daniel @ [
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


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

vB 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
Object Reflection: Creating new instances Java Tip java.lang 0 04-23-2008 09:13 PM
Object from String (calling method dynamically) Java Tip Java Tips 0 02-16-2008 10:22 PM
Naming object instances oldgit New To Java 9 02-08-2008 12:18 AM
method calling? frejon26 New To Java 4 01-25-2008 04:38 AM
Help with Calling a method Albert New To Java 3 07-10-2007 04:27 PM


All times are GMT +3. The time now is 10:17 PM.


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