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:
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started