Re: sorting using comparable
I tried executing your code. Works for me.
I think that you are not putting the files in the right package folders.
Try executing them by putting them under comparable/ex01/Testing.java and comparable/ex01/Person.java
should work.
Other thing.. as you said you are new to java I hope that you have set the classpath correctly.
Re: sorting using comparable
hi.... I created package/ex01/Person.java and it compiled.
however when I try package/ex01/Testing.java it is not compiling
C:\Users\comparable\ex01>javac Te
Testing.java:9: cannot find symbol
symbol : class Person
location: class comparable.ex01.Testing
Person[] persons = new Person[4];
^
Testing.java:9: cannot find symbol
symbol : class Person
location: class comparable.ex01.Testing
Person[] persons = new Person[4];
^
Testing.java:10: cannot find symbol
symbol : class Person
location: class comparable.ex01.Testing
persons[0] = new Person();
^
Testing.java:15: cannot find symbol
symbol : class Person
location: class comparable.ex01.Testing
persons[1] = new Person();
^
Testing.java:20: cannot find symbol
symbol : class Person
location: class comparable.ex01.Testing
persons[2] = new Person();
^
Testing.java:25: cannot find symbol
symbol : class Person
location: class comparable.ex01.Testing
persons[3] = new Person();
^
Testing.java:33: cannot find symbol
symbol : class Person
location: class comparable.ex01.Testing
Person person = persons[i];
^
Testing.java:46: cannot find symbol
symbol : class Person
location: class comparable.ex01.Testing
Person person = persons[i];
^
8 errors
please let me know where I am going wrong
Re: sorting using comparable
It works fine on my machine. Here is what I get as output:
Code:
E:\java-work\comparable\ex01>javac Person.java
E:\java-work\comparable\ex01>javac Testing.java
E:\java-work\comparable\ex01>java Testing
Natural Order
Goodyear, Elvis. Age:56
Clark, Stanley. Age:8
Graff, Jane. Age:16
Goodyear, Nancy. Age:69
Sorted by age
Clark, Stanley. Age:8
Graff, Jane. Age:16
Goodyear, Elvis. Age:56
Goodyear, Nancy. Age:69
E:\java-work\comparable\ex01>
I had the same problem previously. Everything worked fine after setting the classpath correctly.
Here are some links which might help you.
http://forums.sun.com/thread.jspa?threadID=670019
http://forums.sun.com/thread.jspa?threadID=753450
http://www.sharkyforums.com/showthread.php?t=281641
Try including the current directory in your classpath.
Re: sorting using comparable
Thanks for the help! The first thread showed me how to fix the problem. I used
javac -cp . comparable/ex01/Testing.java to compile
I dint change the path because it worked fine for many other java programs.
Re: sorting using comparable
You need your classpath set correctly. You may find this tutorial helpful: Path & Classpath.
The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time...
T. Cargill