Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1.4: Java: (code pasted below) Consider a square with the lower left corner at the origin, and with length s. A point is considered

Exercise 1.4: Java: (code pasted below) Consider a square with the lower left corner at the origin, and with length s. A point is considered within the square if its inside or on the one of the edges. Write a method inside the XYPoint class so that the following code in main() works:

image text in transcribed

Code:

public static void main (String[] argv) {

XYPoint p = new XYPoint ();

p.x = 2; p.y = 3;

boolean yes = p.isWithin (5);

System.out.println (yes); // should be true

XYPoint q = new XYPoint ();

q.x = 5; q.y = 7;

yes = q.isWithin (5);

System.out.println (yes); // should be false

XYPoint z = new XYPoint ();

z.x = 8; z.y = 9;

yes = z.isWithin (5);

System.out.println (yes); // should be false

}

Exercise 1.4: Consider a square with the lower left corner at the origin, and with length s . A point is considered within the square if it's inside or on the one of the edges, as in this diagranm (5,7) ( 5,3) 2,.3) Write a method inside the XYPoint class so that the following code in main) works: public static void main (String[C] argv) xYPoint p-new XYPoint O; boolean yes -p.isWithin (5); System.out.println (yes); // should be true XYPoint q-new XYPoint O; yes-q.isWithin (5) System.out.println Cyes); 7 should be false XYPoint znew XYPoint O; yes - z.isWithin (5); System.out.println Cyes) / should be false The method isWithinO takes in the length of the square's side

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

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions