aspose file tools*
The moose likes Applets and the fly likes Program Anomaly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Program Anomaly" Watch "Program Anomaly" New topic
Author

Program Anomaly

Milaffyd
Greenhorn

Joined: Aug 14, 2001
Posts: 3
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);
}
}
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
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

Joined: Aug 14, 2001
Posts: 3
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Program Anomaly
 
Similar Threads
How to plot a graph in Java ?
"Drawing" Points on screen
Could someone give this piece of code a look?
Set Pixel(x, y) to color c
Drawing with mouse