• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

class practice

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[URL removed. Lines too long. See response below. (Knute)]

The exercises website is above. below is question 3 and 4.

Object class(MyPoint)- http://pastebin.com/VcvdXzFF
Class which object is a variable- http://pastebin.com/TdebBt9X
Main method http://pastebin.com/tRS195ur

I need help with the last two methods of question 3.
and I don't know how to do 3 methods in question 4: getCenterX(),GetCenterY(),getCenterXY().

thanks a lot for all who will help me.
 
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

This is the preferred way to post a question with code.

Actual URL to questions, not copied from Google results page: http://www.ntu.edu.sg/home/ehchua/programming/java/J3f_OOPExercises.html

Code pasted with code tags.



What are your specific questions?
 
Jhon Schmidt
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
these are the questions for the class you wrote (MyPoint), I need to add these two methods
1.A method called distance(int x, int y) that returns the distance from this point to another point at the given (x, y) coordinates.
2.An overloaded distance(MyPoint another) that returns the distance from this point to the given MyPoint instance another.
 
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For 1)add a method:
double distance(int x,int y)
{
//calculate distance between this and
//method parameter,return thedistance
}
2)add another method:
double distance(MyPoint m)
{
//CALCULATE DISTANCE BETWEEN
//this and and instance variable of m
//reference
//return the distance
}



Be careful while invoking distance method with reference of MyPoint as its argument.
 
Jhon Schmidt
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sachin Tripathi wrote:For 1)add a method:
double distance(int x,int y)
{
//calculate distance between this and
//method parameter,return thedistance
}
2)add another method:
double distance(MyPoint m)
{
//CALCULATE DISTANCE BETWEEN
//this and and instance variable of m
//reference
//return the distance
}




Yeah man I understand what you wrote but I really need the body of the method, I dont know how to do that.

 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Yeah man I understand what you wrote but I really need the body of the method, I dont know how to do that.


JavaRanch is NotACodeMill (← that's a link) so we don't provide complete solutions, but we can help you find that answer yourself. ShowSomeEffort by writing as much of the method as you can, or asking a specific question.
 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did this search:

formula for distance between two points

And found several sites that give you a generic distance formula. You can use that in your double distance(int x,int y) method.
 
Sachin Tripathi
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try it yourself, and believe me you'll get it easily
And even if you fail( which you are not going to) post your specific question here,we are good people (atleast me and knute surely are )we will help you
 
Jhon Schmidt
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, this is what I wrote.



and here is what I wrote in the main method:


this is the error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The target type of this expression must be a functional interface
Syntax error on token "Invalid Character", :: expected
The target type of this expression must be a functional interface
Syntax error on token "Invalid Character", :: expected

at MyPoint.distance(MyPoint.java:39)
at main.main(main.java:108)

What should I do? what's the problem?
It looks like it has a problem with these two lines:

 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code you posted looks good. Could you post all of the code and maybe we can figure out what's happening.
 
Sachin Tripathi
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't see any problem with what you did
It is compiling without error and giving accurate result
You might be doing wrong at someother places(recheck the signature of your main method)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic