Question
plz fix the first picture codes and use the point methods to pass the tests at the bottom thank you! public class Point{ private int
plz fix the first picture codes and use the point methods to pass the tests at the bottom 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 class Rectangle implements Shape { private int length; //length units along x axis private int width; //width units along y axis private Point position; // position is the (x,y) coordinates of lower left corner of the rectangle public Rectangle() { this.length = 0; this.width = 0; this.position = new Point(); public Rectangle (int length, int width) { this.length = length; this.width = width; this.position = new Point(); } public Rectangle(int length, int width, Point position) { this.length = length; this.width = width; this.position = position; public double area () { return length * width; } public double perimeter() { return ((length + width) * 2); } public boolean contains (Point pt) { int ptX = pt.getX(); int ptY = pt.getY(); int positionX = position.getX(); int positiony = position.getY(); int xDistance = ptx-positionx; int yDistance = pty-positionY; if ((xDistance + yDistance)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