• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

Object Arrays

Todd Smith Todd
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need help I am working on a program for class. I need to Pass data in a object array from my Main Driver to class in a package but I can get my code to work. I need all the help I can get. From some reason when I loop back thru the array I alwasy get to last thing I load in to the array in any position I look at it the array if that make sence.

Here is the test data

123Smith, Jimmy C 8.012.0 0.0 2.0
166Render, MeleneC10.015.0 0.0 0.0
166Render, MeleneS 0.0 0.0 5.0 0.0
184Towner, John C 0.0 0.0 9.7 7.2
184Towner, John S 4.6 7.8 1.5 1.9
234Hope, Susan S 0.0 0.0 2.0 0.0
278Jones, Tom W 0.0 0.0 8.9 0.0
341Wilson, ClaudeS 0.0 0.0 0.0 5.0
345Higins, Bill C 1.0 1.0 1.0 1.0
345Higins, Bill S 2.0 2.0 2.0 2.0
456Bean, Ryan S 0.0 3.0 4.0 0.0
479Kringle, ChrisS 0.0 0.0 5.0 0.0
479Kringle, ChirsW 0.0 1.3 0.0 0.0
501George, Paul S14.9 7.4 8.7 9.4
501George, Paul W 0.0 0.0 0.0 4.5

[ EJFH: Edited to add CODE tags for formatting ]
[ November 30, 2004: Message edited by: Ernest Friedman-Hill ]
Ernest Friedman-Hill
author and iconoclast
Posts: 24204
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is happening because you made all the member variables in the class BillRecord static. That means that all the objects of that class share the same copies of these variables, so no matter how many you construct, they'll all always have the same set of values: the ones assigned to the last one constructed.

To fix, just make all the members of BillRecord non-static.

Note that static variables are the exception, rather than the norm. Furthermore, functions shouldn't commnicate through static variables as if they were global variables in some other language. In general, make members non-static whenever possible, and also use local variables defined in a method in preference to member variables defined in a class whenever you can.
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    Bookmark Topic Watch Topic
  • New Topic