| Author |
compile error
|
jamie keene
Greenhorn
Joined: Feb 15, 2011
Posts: 28
|
|
I think i have the codes right, and the main method was provided, yet i am getting errors in both methods
this compiles with no error
this is the provided main method, which i can not compile
error is :
----jGRASP exec: javac -g LandTractDemo.java
LandTractDemo.java:20: cannot find symbol
symbol : class LandTract
location: class LandTractDemo
LandTract tract1 = new LandTract(length, width);
^
LandTractDemo.java:20: cannot find symbol
symbol : class LandTract
location: class LandTractDemo
LandTract tract1 = new LandTract(length, width);
^
LandTractDemo.java:28: cannot find symbol
symbol : class LandTract
location: class LandTractDemo
LandTract tract2 = new LandTract(length, width);
^
LandTractDemo.java:28: cannot find symbol
symbol : class LandTract
location: class LandTractDemo
LandTract tract2 = new LandTract(length, width);
^
4 errors
----jGRASP wedge: exit code for process is 1.
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2928
|
|
|
Have you defined the CLASSPATH variable? If yes, what is its value?
|
Mohamed Sanaulla | My Blog
|
 |
Suresh Sajja
Ranch Hand
Joined: May 12, 2009
Posts: 34
|
|
compiler cant find class LandTract. we have to add user classes to the class path.
try using -cp option with javac
to include current directory to class path, use "."
|
~Suresh
|
 |
jamie keene
Greenhorn
Joined: Feb 15, 2011
Posts: 28
|
|
so i got it to work, i had miss named something in one of the files, but now it is returning an area of 0.0
return looks like this
----jGRASP exec: java LandTractDemo
Enter the length and width of Tract 1: 10 20
Enter the length and width of Tract 2: 15 25
TRACT 1: length is 10.0, width is 20.0, area is 0.0
TRACT 2: length is 15.0, width is 25.0, area is 0.0
The tracts are NOT the same size
----jGRASP: operation complete.
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3793
|
|
The problem with the way you've written it at the moment is that the area member variable of LandTract doesn't get initialised until you call getArea(), and you're not calling that.
There are a couple of simple fixes I could suggest:
1. Set area = length*width in the constructor, and in getArea() just return the value of area without doing the calculation.
or
2. Get rid of the area variable. The body of getArea() becomes just return length*width. In toString, call getArea() insetad of using area.
I'd usually go for 2, as that way you don't have a seperate variable that needs to be kept in sync with length and width.
|
 |
jamie keene
Greenhorn
Joined: Feb 15, 2011
Posts: 28
|
|
thank you, that helped, but now i am stuck on doing a margin of error
this is what i have
but i know that i cant do (tract1 - tract2) but i dont think i can do margin of error with tract1.compareTo(tract2)
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3793
|
|
|
Line 36 should be tract1.getArea() - tract2.getArea(), shouldn't it? Otherwise it looks about right.
|
 |
jamie keene
Greenhorn
Joined: Feb 15, 2011
Posts: 28
|
|
|
thanks!
|
 |
 |
|
|
subject: compile error
|
|
|