• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

distance formula class reward

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need help with a distance formula class: d=square root of (x2-x1)^2+(y2-y1)^2
My skype is XXXXX there will be a reward for helping me.
 
Rancher
Posts: 4739
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I need help


Please explain what you are having problems with.
 
Jennings Cavil
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't figure out why I have so many errors for my class.
 
Norm Radder
Rancher
Posts: 4739
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

why I have so many errors


Please copy the full text of the error messages and paste them here.

Also please wrap any posted code in code tags: https://coderanch.com/wiki/659781/Wiki/Code-Tags
 
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Agreed. The compiler is your friend here. You need to work through the compiler error messages.

Regardless, just a quick eyeball of the code, I see lots of variables that haven't been declared; and a few methods attempted to be defined within an instance initializer (which is not allowed).

Henry
 
Jennings Cavil
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you skype message me? its easier its just my name
 
Norm Radder
Rancher
Posts: 4739
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, the idea here is to publicly help people solve problems so that the others can read all about it and learn.

That means: No private communications.
 
Jennings Cavil
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DistanceFormulaMC.java:8: illegal start of expression
     public DistanceFormulaMC( double x1, double y1, double x2, double y2)
     ^
DistanceFormulaMC.java:8: '.class' expected
     public DistanceFormulaMC( double x1, double y1, double x2, double y2)
                                      ^
DistanceFormulaMC.java:8: ';' expected
     public DistanceFormulaMC( double x1, double y1, double x2, double y2)
                                        ^
DistanceFormulaMC.java:8: <identifier> expected
     public DistanceFormulaMC( double x1, double y1, double x2, double y2)
                                                    ^
DistanceFormulaMC.java:8: not a statement
     public DistanceFormulaMC( double x1, double y1, double x2, double y2)
                                                            ^
DistanceFormulaMC.java:8: ';' expected
     public DistanceFormulaMC( double x1, double y1, double x2, double y2)
                                                              ^
DistanceFormulaMC.java:8: ';' expected
     public DistanceFormulaMC( double x1, double y1, double x2, double y2)
                                                                         ^
DistanceFormulaMC.java:15: illegal start of expression
     public void calcDistance()
     ^
DistanceFormulaMC.java:15: illegal start of expression
     public void calcDistance()
            ^
DistanceFormulaMC.java:15: ';' expected
     public void calcDistance()
                             ^
DistanceFormulaMC.java:19: reached end of file while parsing
}      
^
11 errors
 
Henry Wong
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jennings Cavil wrote:DistanceFormulaMC.java:8: illegal start of expression
     public DistanceFormulaMC( double x1, double y1, double x2, double y2)
     ^



The first error is caused by trying to declare a method within an instance initializer.  And BTW, if you haven't learned what is an instance initializer yet, then ... you have an issue with parenthesis. You accidentally opened a block after your instance variable declarations.

Henry
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a number of things wrong with the syntax of your code. You should review your basic knowledge of Java syntax and concepts first. A good place to learn the basics is Oracle's Java Tutorials.

Here are my remarks, looking at your code:

Jennings Cavil wrote:I can't figure out why I have so many errors for my class.


Why do you have an opening brace { in line 7? Remove it.

In line 17, in the calcDistance() method, you are using variables x1, x2, y1, yt which are not declared at that point. The constructor (lines 8 - 14) does have argument variables x1, y1, x2, y2 (not yt) but these are variables local to the constructor, which are not available in other methods in the class.

You should use the member variables in the calcDistance() method instead.

You need to be really precise when writing a program. Computers are dumb machines, which get confused when you don't give them exactly what they need. Be careful that you get all the details exactly right - no extra {, use the exactly correct variable names, etc.

Besides the syntax problems, there are some things conceptually wrong with your class. Suppose you fix the syntax errors, then the class is still not very useful; the calcDistance() method assigns its result to a private member variable, but there is no way to get the result of the calculation out of the class (private member variables are not accessible outside of a class).
 
Marshal
Posts: 75716
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jennings Cavil wrote:. . . My skype is XXXXX there will be a reward for helping me.

Please don't try to contact people outside the forum; I have removed the address. Don't post the same question twice; there is useful in formation in your other thread which you are going to lose because the question appears twice.
 
To get a wish, you need a genie. To get a genie, you need a lamp. To get a lamp, you need a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic