to anyone who can help me out with this its of no big importance i was stumbling one day and this came across this little snit bit of what looks to be like a program or something so i tried starting it and i have no idea whats going on with it lol and i took java in school lol anywho im tired of it bugging me so if any one could give me a hand that would be great thank you........

Fully implement the class named Point with private members of type double called X and Y. Each Point shall represent a point in the Cartesian co-ordinate system.

The class should have the public operation called distance which takes an object of class point as a parameter and returns a double representing the distance between the two points.

Write a small driver application which prompts the user for the X and Y values of 4 points from the keyboard, outputs the points, and outputs the distances between each of the 4 points.

X and Y values shall be prompted for one at a time.
Duplicate Points, that is, Points with the exact same X and Y values are disallowed. If the user enters values for an existing points, display an error message and prompt again. Note: both the X AND Y values must be the same for a duplicate Point .

Your main program shall output the distances between each set of points using the distance method. Duplicate distances are not allowed. (ie if the distance from pt1 to pt2 is output, the distance from pt2 to pt2 should not be output).

Hint: There are more than 4 possible distances.

Note: points may be in anywhere in the cartesian co-ordinate system. That is, X and/or Y values may be negative or positive.

-Create a default, and non-default constructor.
-Create a toString method that outputs that point's information.

8 Years
Discussion Span
Last Post by chickenmcnugget

Sorry, not going to do your homework assignment for you.

If you want to post what code you do have done and ask specific questions, someone may be able to provide some advice.


its not my homework i said i stumbled upon it an add on from mozilla lol im not asking for any homework to do hahahaha that was said last time i posted kinda why ive been holding off i cant give you code cause all my code is wrong lol why im being stumped by it i was just doing for fun cause it caught my attention its not homework for the 2nd time ive been told that on this website just looking for some helping hands to grasp it a lil better but thank you for your commenting and remark though it wasnt very helpful

I call BS. Also, learn to write an intelligent sentence.

ok so i have gotten some of it done with some help from a couple of friends but they are even stumped on the rest

import java.lang.Math.*;

class Point
//doubles to hold points x and y
private double x, y;

//default constructor
public Point()
setPoint(0, 0);

//non default constructors are ( x and y)
public Point(double cordx, double cordy)
setPoint(cordx, cordy);

// mutator point
public void setPoint(double cordx, double cordy)
x = cordx;
y = cordy;

//mutator x
public void setx(double cordx)
x = cordx;

//mutator y

public void sety(double cordy)
y = cordy;

//method that calculates distance
public double distance(Point otherPoint)
double distance;

distance = Math.sqrt(Math.pow(x - otherPoint.x, 2) +
Math.pow(y - otherPoint.y, 2));

return distance;

// equals method
public boolean equals(Point otherPoint)
if(x == otherPoint.x && y == otherPoint.y)
return true;
return false;

//toString method
public String toString()
String str = "";

str = str + "The x coordinate of the point is " + x + ". ";
str = str + "The y coordinate of the point is " + y + ".";

return str;
}//end class

Edited by happygeek: fixed formatting

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.