This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Program Anomaly

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.

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?
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.
Let's get him boys! We'll make him read this tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic