Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compile error

 
jamie keene
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you defined the CLASSPATH variable? If yes, what is its value?
 
Suresh Sajja
Ranch Hand
Posts: 34
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 "."
 
jamie keene
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4567
8
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4567
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 36 should be tract1.getArea() - tract2.getArea(), shouldn't it? Otherwise it looks about right.
 
jamie keene
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic