Question: 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:

Exercise 1.4: Java: (code pasted below) Consider a square with the lower

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

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!