Click to See Complete Forum and Search --> : Trouble passing arrays!?


dantheman88
November 7th, 2006, 05:04 PM
I've written a test app to check a class but the app compiles with this error:
and I can't figure out how to fix it. I'm thinking it has something to do with my array setup. Anyone have any ideas? I'd really appreciate it


Test.java:5: cannot find symbol
symbol : variable A_call
location: class Test
A_call.Alist = new A_call();
^
Test.java:5: cannot find symbol
symbol : class A_call
location: class Test
A_call.Alist = new A_call();
^
Test.java:6: cannot find symbol
symbol : variable Alist
location: class Test
double a_value = Alist[100];


Here's the test code:

public class Test
{
public static void main (String [] args)
{
A_call.Alist = new A_call();
double a_value = Alist[100];
System.out.println(+a_value);
}
}


and the class itself:

public class ElectionMod2
{


//x = television advertising
//y = get out the vote
//z = dirty tricks

double[] Alist = new double[241];
double[] Blist = new double[241];
double[] Clist = new double[241];

public ElectionMod2()
{
for(int x = 0; x <= 10; x++)
{
for(int y = 0; y <= 20; y++)
{
for(int z = 0; z <= 4; z++)
{
int price = 100000*x + 50000*y + 250000*z;

if(price <= 1000000)
{

for(int i=0; i< Alist.length; i++)
{

if( 2 <= x && x < 4 && 4 <= y && y < 8)
{
Alist[i] = 0.01;
}

if( 4 <= x && x < 6 && 8 <= y && y < 12)
{
Alist[i] = 0.02;
}

else if( 6 <= x && x < 8 && 12 <= y && y < 16)
{
Alist[i] = 0.03;
}

else if( 8 <= x && x < 10 && 16 <= y && y < 20)
{
Alist[i] = 0.04;
}

else if( 10 <= x && 20 <=y)
{
Alist[i] = 0.05;
}

else
{
Alist[i] = 0;
}
}


for(int j=0; j > Blist.length; j++)
{


if (4 <= x && x < 8)
{
Blist[j] = 0.01;
}

else if (8 <= x)
{
Blist[j] = 0.02;
}

else
{
Blist[j] = 0;
}
}


for(int k=0; k > Clist.length; k++)
{


if (2 <= x && x < 4 && 1 == z)
{
Clist[k] = 0.01;
}

else if (4 <= x && x < 6 && 2 == z)
{
Clist[k] = 0.02;
}

else if (6 <= x && x < 8 && 3 == z)
{
Clist[k] = 0.03;
}

else if (8 <= x && 4 == z)
{
Clist[k] = 0.04;
}

else
{
Clist[k] = 0;
}
}

}

else
{
//System.out.println("over");
}
}
}
}
}

public double[] A_call()
{
return Alist;
}

public double[] B_call()
{
return Blist;
}

public double[] C_call()
{
return Clist;
}

}

dlorde
November 7th, 2006, 06:30 PM
The error is because you're trying to create an instance of a method as if it was a class. That's not possible in Java (and if it was what would it mean?). I'm not going to try and figure out what the rest of your code does because on the very next line you try to assign an array of 100 Alist to a double variable - but the syntax is wrong anyway. You can't do that either, it's not Java and it doesn't make any sense... and the line after that isn't Java, either...

If you want help with your code, you really need to know basic Java syntax first. We can't teach you that here.

Education is not the filling of a pail, but the lighting of a fire...
W. B. Yeats

kcor
November 7th, 2006, 06:45 PM
I see a lot of things wrong here but I'm just going to say that you really need to do some research on how to write proper java code. Many things in your test class just doesn't make sense. My advice is to google 'How to create an instance of a class'...which is one of the FIRST things you must do in your test class. Then see if you can figure things out from there...

May I suggest this link:

http://leepoint.net/notes-java/

Hope that helps =)