Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

Explain how SSID works.

Answered: 1 week ago