Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Program Anomaly

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a program that makes use of an extended Vector. This vector stores datapoint objects, each of which contain two double type values: an x and a y. One added function to the Vector allows it to scan itself for x and y maxes, and x and y mins. For some odd reason, it is failing to do this properly and ends up storing values that are not the min nor the max in the data set. I have included the code for the scan. Any takers?
public void dataStats() {
xmax = ((datapoint) this.firstElement()).getx();
xmin = ((datapoint) this.firstElement()).getx();
ymax = ((datapoint) this.firstElement()).gety();
ymin = ((datapoint) this.firstElement()).gety();

Enumeration scan = this.elements();

while (scan.hasMoreElements()) {
datapoint processxy = (datapoint)scan.nextElement();

double y = processxy.gety();
double x = processxy.getx();
xmax = Math.max(x, xmax);
xmin = Math.min(x, xmin);
ymax = Math.max(y, ymax);
ymin = Math.min(y, ymin);
}
}
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eric,
I don't think you need to use the enum stuff. Just get the elements the usual way. Look at the following example that works great.

Regards,
Manfred.
 
Milaffyd
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Manfred.
I tried implementing the good old-fashioned index search via the for loop. The applet still fails to acknowledge the proper maxes and mins. If anything, it seems worse since it's selected a value much less than before for a max. Could it be that some sort of memory error occurring?
http://pubweb.nwu.edu/~eyy830/JavaDev/qrs/qrs.htm
This site is where I post my running applets. Each applet relies on data from its predecessor and performs calculations to get the results you'll see. Hence, why I wonder if it's a memory error from passing vectors repetitively. You'll notice the error if you examine the very last applet panel with a time range between 0 and 1 second. That applet is the only place where I've seen the mistake.
 
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic