• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

compile error

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you defined the CLASSPATH variable? If yes, what is its value?
 
Ranch Hand
Posts: 34
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 4568
9
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks!
 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic