Question: The following Point class has several errors; some are syntax errors and some are incorrect behavior. Find and fix them all. public class Point {

The following Point class has several errors; some are syntax errors and some are incorrect behavior. Find and fix them all.
public class Point{
int x;
int y;
// Returns the distance between this point and (0,0).
public double distanceFromOrigin(){
return Math.sqrt(x * x + y * y);
}
// Shifts this point's location by the given amount.
public void translate(int dx, int dy){
x += dx;
y += dy;
}
}
class PointTest {
public static void main(String[] args){
Point p = new Point();
p.translate(4,3);
Point p1= new Point();
p1.translate(2,3);
Point p2= new Point();
p2.translate(5,7);
Point p3= new Point();
p3.translate(9,4);
System.out.println("Distance from origin of point ("+ p.x +","+ p.y +") is "+ p.distanceFromOrigin());
System.out.println("Distance from origin of point ("+ p1.x +","+ p1.y +") is "+ p1.distanceFromOrigin());
System.out.println("Distance from origin of point ("+ p2.x +","+ p2.y +") is "+ p2.distanceFromOrigin());
System.out.println("Distance from origin of point ("+ p3.x +","+ p3.y +") is "+ p3.distanceFromOrigin());
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!