Question
Java and please fix the highlighted part in the first picture and run it again with the test codes thank you! public class Point{ private
Java and please fix the highlighted part in the first picture and run it again with the test codes thank you!
public class Point{
private int x; private int y; public Point(){ this.x = 0; this.y = 0; } public Point(int x, int y){ this.x = x; this.y = y; } public void setX(int x){ this.x = x; } public int getX() { return this.x; } public void setY(int y){ this.y = y; } public int getY() { return this.y; } public String toString() { return "(" + x + "," + y + ")"; }
}
public static void testRectangleContains() { Shape r00 = new Rectangle(); Point p00 = new Point(); Point p23 = new Point(2,3); Shape r45 = new Rectangle(4, 5, p23);
boolean result; result = r00.contains(p00); displayResults(result, "testRectangleContains - true");
result = r00.contains(p23); displayResults(!result, "testRectangleContains - false"); // outside r45 Point p15 = new Point(1,5); Point p49 = new Point(4,9); Point p42 = new Point(4,2); Point p75 = new Point(7,5);
result = r45.contains(p15); displayResults(!result, "testRectangleContains - false"); result = r45.contains(p49); displayResults(!result, "testRectangleContains - false"); result = r45.contains(p42); displayResults(!result, "testRectangleContains - false"); result = r45.contains(p75); displayResults(!result, "testRectangleContains - false"); // inside/on r45 Point p25 = new Point(2,5); Point p48 = new Point(4,8); Point p43 = new Point(4,3); Point p65 = new Point(6,5); Point p45 = new Point(4,5); result = r45.contains(p23); displayResults(result, "testRectangleContains - true"); result = r45.contains(p25); displayResults(result, "testRectangleContains - true"); result = r45.contains(p48); displayResults(result, "testRectangleContains - true"); result = r45.contains(p43); displayResults(result, "testRectangleContains - true"); result = r45.contains(p65); displayResults(result, "testRectangleContains - true"); result = r45.contains(p45); displayResults(result, "testRectangleContains - true");
}
public static void testRectangleToString() { Shape r00 = new Rectangle(); Point p00 = new Point(); Point p23 = new Point(2,3); Shape r45 = new Rectangle(4, 5, p23); String result = r00.toString(); String expected = "Rectangle of dimensions: 0 by 0 at Point: " + p00.toString(); displayResults(result.equals(expected), "testRectangleToString"); result = r45.toString(); expected = "Rectangle of dimensions: 4 by 5 at Point: " + p23.toString(); displayResults(result.equals(expected), "testRectangleToString"); }
public static void testRectangleToString() { Shape r0o = new Rectangle(); Point poo = new Point(); Point p23 = new Point (2,3); Shape 145 = new Rectangle(4, 5, p23); String result = roo.toString(); String expected = "Rectangle of dimensions: O by O at Point: " + poo.toString(); displayResults (result.equals(expected), "testRectangleToString"); result = r45.toString(); expected = "Rectangle of dimensions: 4 by 5 at Point: " + p23.toString(); displayResults (result.equals (expected), "testRectangleToString")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