Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to Resolve symbols

Status
Not open for further replies.

Rhoon

Programmer
Mar 23, 2001
55
US
hey all, I was hoping someone could point out as to what I'm doing wrong with this program. I've put all the code into one file, should I split them up? I've tried to compile them both on Jbuilder 5 and Sun's JDKv1.4. I keep getting some of the following errors..


Thanks in advance for any help anyone can offer.

Rhoon

<------------begin errors -------------->

program1.java:90: cannot resolve symbol
symbol : variable getlength
location: class array_to_search
for(int i = 0; i < c.getlength ; i++) {c = generator.nextInt(10000) -
5000;}
^
program1.java:90: array required, but array_to_search found
for(int i = 0; i < c.getlength ; i++) {c = generator.nextInt(10000) -
5000;}

<------------begin code -------------->
import java.util.Random;

class array_to_search{


array_to_search(int amount) {

int [] arr = new int[amount];
int index =0;
int num = 1;
int min = amount;
int arraylength = amount;

}


void incrementindex () {

index++;

}

void incrementnum () {

num++;

}
int getlength() { return arraylength;}


int getnum () {

return num;

}

int getindex() {

return index;

}

int getmin () {

return min;

}

int getarrayposition() { return arr[index]; }

void setmin (int mini) {

min = mini;

}

void resetnumindex () {

num = 1;

}


}




class timearray {

public static void main (String args[]) {

Random generator = new Random();

array_to_search a = new array_to_search(100);

array_to_search b = new array_to_search(1000);
array_to_search c = new array_to_search(5000);
array_to_search d = new array_to_search(10000);
array_to_search e = new array_to_search(25000);




for(int i = 0; i < a.getlength ; i++) {a = generator.nextInt(200) - 100;}

for(int i = 0; i < b.getlength ; i++) {b = generator.nextInt(2000) - 1000;}
for(int i = 0; i < c.getlength ; i++) {c = generator.nextInt(10000) - 5000;}
for(int i = 0; i < d.getlength ; i++) {d = generator.nextInt(20000) - 10000;}
for(int i = 0; i < e.getlength ; i++) {e = generator.nextInt(50000) - 25000;}


long start = System.currentTimeMillis();


for (int j = a.getindex(); j < a.getlength ; j = a.incrementindex()) {

if ( a.getarrayposition < a.getmin()) { a.setmin(a.getarrayposition); a.resetnum();}

else if ( a.getarrayposition == a.getmin()) { a.incrementnum(); }

}

long end = System.currentTimeMillis();
long elapsedTime = (end - start);
System.out.println(&quot;It took &quot; + elapsedTime + &quot; milli-seconds to find that &quot; + a.getmin() + &quot; is the lowest number and it occured &quot; + a.getnum() + &quot; times.&quot;);




}}
 
First problem is that you do not have any class defined as public. Since timearray has a main() method I am assuming that should want that to be the public class.

Second problem is that you will need to name your file the same as the public class, in other words timearray.java.

Lastly, your biggest problem is you are trying to access numerous variables out of scope. An example is incrementindex() you are trying to access the index variable that is defined array_to_search() constructor. This needs to be a class variable otherwise it is out of scope when the call to array_to_search() returns. You do this numerous times throughout your code.

If you clean up those errors and you are still having problems than write back and someone will help you. Wushutwist
 
import java.util.Random;

class array_to_search{
int index =0;
int num = 1;
int min = 0;
int arraylength=0;
int [] arr;
public array_to_search(int amount) {

arr = new int[amount];
min = amount;
arraylength = amount;

}

private void incrementindex () {

index++;

}

private void incrementnum () {

num++;

}
private int getlength() { return arraylength;}


private int getnum () {

return num;

}

private int getindex() {

return index;

}

private int getmin () {

return min;

}

private int getarrayposition()
{
if (index>=this.getlength())
return arr[this.getlength()-1];
else
return arr[index];
}

private void setmin (int mini) {

min = mini;

}

private void resetnumindex () {

num = 1;

}


public static void main (String args[]) {

java.util.Random generator = new java.util.Random(System.currentTimeMillis());

array_to_search a = new array_to_search(100);
array_to_search b = new array_to_search(1000);
array_to_search c = new array_to_search(5000);
array_to_search d = new array_to_search(10000);
array_to_search e = new array_to_search(25000);


for(int i = 0; i < a.getlength() ; i++) {a.arr = (int)(generator.nextDouble()*201)-100;} //-100
System.out.println(a.arr[a.getlength()-1]);

for(int i = 0; i < b.getlength() ; i++) {b.arr = (int)(generator.nextDouble()*2001) - 1000;}
System.out.println(b.arr[b.getlength()-1]);

for(int i = 0; i < c.getlength() ; i++) {c.arr = (int)(generator.nextDouble()*10001) - 5000;}
for(int i = 0; i < d.getlength() ; i++) {d.arr = (int)(generator.nextDouble()*20001) - 10000;}
for(int i = 0; i < e.getlength() ; i++) {e.arr = (int)(generator.nextDouble()*50001) - 25000;}


long start = System.currentTimeMillis();
/*
for (int j = a.getindex(); j < a.getlength() ; a.incrementindex()) {

if ( a.getarrayposition() < a.getmin()) { a.setmin(a.getarrayposition()); a.resetnumindex();}

else if ( a.getarrayposition() == a.getmin()) { a.incrementnum(); }
*/
}

long end = System.currentTimeMillis();
long elapsedTime = (end - start);
System.out.println(&quot;It took &quot; + elapsedTime + &quot; milli-seconds to find that &quot; + a.getmin() + &quot; is the lowest number and it occured &quot; + a.getnum() + &quot; times.&quot;);

}// end of public static void main
}// end of array_to_search

I correct most of the errors for you and i found there is some logical error in searhing for number with minimum value
(I remark them with /* */) press ctl+c to break program.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top