Results 1 to 4 of 4
 06012011, 08:24 PM #1Member
 Join Date
 Jun 2011
 Posts
 10
 Rep Power
 0
HELP with a plotter program ASAP!
I'm SUPER lost on this project and keep getting this error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at Plotter.main(Plotter.java:3)
Here's the assingment:
Create a simple plotter (xaxis runs vertically, y axis runs horizontally) using command line arguments for a (left end point), b (right end point), and n (number of subintervals of [a, b].)
Steps:
compute maximum and minimum values of the function on [a, b].
compute scaling factor sf. For example, does the following accomplish all we need?
sf = graphPageWidth/(max  min).
construct for each point in the interval the required number of spaces (one for each column) preceding the plot (an *)
#cols = sf ( f(a +idx)  min ).
and here's my code:public class Plotter {
public static void main(String[] args) {
double a = Double.parseDouble(args[0]);
double b = Double.parseDouble(args[1]);
double x, sf, y;
double max;
double min;
double nSpaces;
int n = Integer.parseInt(args[2]);
System.out.println(" "+args[0]+" "+args[1]+" "+args[2]);
double dx = (ba)/n;
max=0;
min=0;
for (int i =0; i<=n; i++) {
x= a + i * dx;
y= x*x*x;
if (y>max) {
max=y;
}
else if (y<min) {
min=y;
}
}
sf = 120/(max  min);
System.out.println(dx);
System.out.println(max);
System.out.println(min);
for(int k=0; k<=n; k++) {
x = a + k * dx;
y = x*x*x;
nSpaces = (y  min) * sf;
int j = 0;
if(j<nSpaces)
{
System.out.print(" ");
j++;
}
else {
System.out.println("*");
}
}
}
}
 06012011, 08:35 PM #2Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at Plotter.main(Plotter.java:3)
It says that at line 3 of your program there is an array that does not have a 0th element. In other words the array is empty.
You should test if the length of the array is greater than 0 before trying to get the 0th element.
What do you expect to be in the args array?
Are you passing arguments to your program when you start its execution?
 06012011, 08:42 PM #3
 06032011, 12:16 AM #4Member
 Join Date
 Jun 2011
 Posts
 10
 Rep Power
 0
Similar Threads

Help with Polynomial Graph Plotter and its scaling
By sojharo in forum Java 2DReplies: 0Last Post: 01232011, 09:14 PM 
Need help ASAP, please
By KAM0002 in forum New To JavaReplies: 6Last Post: 12082010, 04:58 PM 
Need help asap please!
By mbm4ever in forum Java AppletsReplies: 4Last Post: 08122010, 03:57 PM 
Assistance needed ASAP: Postpix program
By Debonairj in forum New To JavaReplies: 18Last Post: 07272010, 01:37 PM 
Need help ASAP with Payroll Program Part 2
By arrech326 in forum New To JavaReplies: 10Last Post: 11172009, 10:17 PM
Bookmarks