Question: INTRO TO JAVA QUESTION: Consider the Point class partially defined below. Complete the getDistanceFromOrigin() methods according to the instruction. Suppose the formula that calculates the

INTRO TO JAVA QUESTION:

Consider the Point class partially defined below. Complete the getDistanceFromOrigin() methods according to the instruction. Suppose the formula that calculates the distance between two points (x1, y1) and (x2, y2) is given.

CODE:

public class Point { private int x; // x-coordinate of point private int y; // y-coordinate of point public Point(int px, int py) { x = px; y = py; } /** The getDistanceFromOrigin() method returns the distance between (0,0) and this point (x,y). */ public double getDistanceFromOrigin() { // Your work goes here. } }
public class Circle { private double radius; // radius of this circle public Circle(double r) { radius = r; } /** * Calculates the area of this circle and returns it. * @return the area of this circle */ public double getArea() { } }

TESTER:

public class ShapeTester { public static void main (String [] args) { Point p = new Point (10,20); System.out.println("Distance from origin: " + p.getDistanceFromOrigin()); Circle c = new Circle(2.5); System.out.println("Area is " + c.getArea()); } } 

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 Databases Questions!