Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. For the following program, draw a stack diagram showing the state of the program just before distance returns. Include all variables and parameters and

1. For the following program, draw a stack diagram showing the state of the program just before distance returns. Include all variables and parameters and the objects those variables refer to.

2. What is the output of this program?

public static double distance(Point p1, Point p2) {

int dx = p1.x - p2.x;

int dy = p1.y - p2.y;

return Math.sqrt(dx*dx + dy*dy); }

public static Point findCenter(Rectangle box) {

int x = box.x + box.width/2;

int y = box.y + box.height/2;

return new Point(x, y); }

public static void main(String[] args) {

Point pnt = new Point(5, 8);

Rectangle rect = new Rectangle(0, 2, 4, 4);

Point center = findCenter(rect);

double dist = distance(center, pnt);

System.out.println(dist); }

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_2

Step: 3

blur-text-image_3

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

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions