4. XY-Rectangle (20 points) A point P in a Cartesian coordinate system can be denoted using...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
4. XY-Rectangle (20 points) A point P in a Cartesian coordinate system can be denoted using its x-coordinate and y-coordinate as (Xp,yp), and an xy-rectangle, i.e., a rectangle with its four sides in parallel or overlapping with the x- and y-axes, can be represented using its top-left vertex Pul and bottom-right vertex Pbr as . For example, xy- rectangle R in Figure 1 (in solid line) can be represented as , while xy-rectangle R2 (in dotted line) can be represented as . Given class Point as defined in XYRectangle.java, please complete class XYRectangle so that each XYRectangle object represents a valid xy-rectangle and supports the following operations: y P1 R2 R1 P4 P2 Figure 1. Two xy-rectangles. 1. A constructor that takes two points as arguments and initializes the newly created xy- rectangle in such a way that the line segment between the two points forms a diagonal of the rectangle; You may assume that the line passing both argument points always intersects with both the x and the y axis. 2. A method toString that returns a String representation of the xy-rectangle in the form , where a point P with coordinates Px and Py is denoted as (Px,Py). For example, given an xy-rectangle with the top-left and bottom-right vertexes at positions (2,3) and (4,1), invoking toString on the xy-rectangle will return " ". 3. A method area that takes no argument and returns the area of the xy-rectangle. 4. A method rotate Clockwise that takes no argument and rotates the current xy-rectangle clockwise by 90 degrees around its top-left vertex; For example, xy-rectangle R in Figure 1 will be at the position of R2 after the method is invoked on R1. 5. A method move that takes two arguments deltax and deltaY and moves the xy-rectangle horizontally by deltax and vertically by deltaY. 6. A method contains that takes a point P as the argument and returns true if and only if the point is within or on the border of the xy-rectangle. 7. A method contains that takes an xy-rectangle R as the argument and returns true if and only if every point contained in R is also contained in the current xy-rectangle. 8. A method overlapsWith that takes an xy-rectangle R as the argument and returns true if and only if at least one point is contained in both R and this xy-rectangle. Note: 3 You may assume that the reference-typed parameters of the constructor or methods are never null. You may define additional methods when you see fit. Tests in XYRectangle Test.java should all pass after you've completed the class. What to do: In XYRectangle.java [Task 6] Complete the constructor as well as the other methods in class XYRectangle. package hk.edu.polyu.comp.comp2021.assignment1. shape; import org.junit.Test; import org.junit.Before; import static org.junit.Assert.*; public class XYRectangle Test { Point [] [] points; XYRectangle r1, r2, r3, r4, r5, r6; private Point getPoint(int x, int y){ return points [x] [y]; } @Before public void init() { } points = new Point [6] [6]; for(int i = 0; i < 6; i++) @Test for(int j = 0; j < 6; j++) { points [i][j] = new Point (i, j); r1 = new XYRectangle(getPoint(x:1,y:2), getPoint(x:3,y:1)); r2 = new XYRectangle(getPoint(x:1,y:2), getPoint(x: 2,y: 1)); r3 = new XYRectangle(getPoint(x:4,y:4), getPoint(x:5,y:3)); public void testConstructor1() { } assertEquals(" ", r1.toString()); @Test public void testArea() { assertEquals(2, r1.area()); } @Test public void testRotateClockwise1 ( ) {\ r1. rotateClockwise(); assertEquals(" ", r1.toString()); } @Test public void testMovel ( ) { r1.move(1,1); assertEquals(" ", r1.toString()); } @Test public void testContains1() { } assertTrue(r1.contains(getPoint(x: 1,y:2))); @Test public void testContains() { } assertTrue(r1.contains(r2)); @Test public void testOverlapsWith1() { } } assertTrue(r1.overlapsWith(r2)); package hk.edu.polyu.comp.comp2021.assignment1. shape; public class XYRectangle { private Point topleft; private Point bottom Right; public Point getTopLeft() { return topLeft; } public Point getBottom Right() { return bottomRight; } public XYRectangle (Point p1, Point p2) { // Todo: complete the constructor } public String toString() { // Todo: complete the method return ""; } public int area() { // Todo: complete the method return 0; } public void rotateClockwise() { // Todo: complete the method return; } public void move(int deltax, int deltaY) { // Todo: complete the method } public boolean contains (Point p) { // Todo: complete the method return false; } public boolean contains (XYRectangle r) { // Todo: complete the method return false; } public boolean overlapsWith(XYRectangle r) { // Todo: complete the method return false; } class Point{ private int x; private int y; public Point (int x, int y) { set(x, y); } public int getX() { return x; } public int getY() { return y; } public void set (int x, int y) { this.x = x; this.y = y; } } public String toString() { } return "(" + getX() + "," + getY() + ")"; 4. XY-Rectangle (20 points) A point P in a Cartesian coordinate system can be denoted using its x-coordinate and y-coordinate as (Xp,yp), and an xy-rectangle, i.e., a rectangle with its four sides in parallel or overlapping with the x- and y-axes, can be represented using its top-left vertex Pul and bottom-right vertex Pbr as . For example, xy- rectangle R in Figure 1 (in solid line) can be represented as , while xy-rectangle R2 (in dotted line) can be represented as . Given class Point as defined in XYRectangle.java, please complete class XYRectangle so that each XYRectangle object represents a valid xy-rectangle and supports the following operations: y P1 R2 R1 P4 P2 Figure 1. Two xy-rectangles. 1. A constructor that takes two points as arguments and initializes the newly created xy- rectangle in such a way that the line segment between the two points forms a diagonal of the rectangle; You may assume that the line passing both argument points always intersects with both the x and the y axis. 2. A method toString that returns a String representation of the xy-rectangle in the form , where a point P with coordinates Px and Py is denoted as (Px,Py). For example, given an xy-rectangle with the top-left and bottom-right vertexes at positions (2,3) and (4,1), invoking toString on the xy-rectangle will return " ". 3. A method area that takes no argument and returns the area of the xy-rectangle. 4. A method rotate Clockwise that takes no argument and rotates the current xy-rectangle clockwise by 90 degrees around its top-left vertex; For example, xy-rectangle R in Figure 1 will be at the position of R2 after the method is invoked on R1. 5. A method move that takes two arguments deltax and deltaY and moves the xy-rectangle horizontally by deltax and vertically by deltaY. 6. A method contains that takes a point P as the argument and returns true if and only if the point is within or on the border of the xy-rectangle. 7. A method contains that takes an xy-rectangle R as the argument and returns true if and only if every point contained in R is also contained in the current xy-rectangle. 8. A method overlapsWith that takes an xy-rectangle R as the argument and returns true if and only if at least one point is contained in both R and this xy-rectangle. Note: 3 You may assume that the reference-typed parameters of the constructor or methods are never null. You may define additional methods when you see fit. Tests in XYRectangle Test.java should all pass after you've completed the class. What to do: In XYRectangle.java [Task 6] Complete the constructor as well as the other methods in class XYRectangle. package hk.edu.polyu.comp.comp2021.assignment1. shape; import org.junit.Test; import org.junit.Before; import static org.junit.Assert.*; public class XYRectangle Test { Point [] [] points; XYRectangle r1, r2, r3, r4, r5, r6; private Point getPoint(int x, int y){ return points [x] [y]; } @Before public void init() { } points = new Point [6] [6]; for(int i = 0; i < 6; i++) @Test for(int j = 0; j < 6; j++) { points [i][j] = new Point (i, j); r1 = new XYRectangle(getPoint(x:1,y:2), getPoint(x:3,y:1)); r2 = new XYRectangle(getPoint(x:1,y:2), getPoint(x: 2,y: 1)); r3 = new XYRectangle(getPoint(x:4,y:4), getPoint(x:5,y:3)); public void testConstructor1() { } assertEquals(" ", r1.toString()); @Test public void testArea() { assertEquals(2, r1.area()); } @Test public void testRotateClockwise1 ( ) {\ r1. rotateClockwise(); assertEquals(" ", r1.toString()); } @Test public void testMovel ( ) { r1.move(1,1); assertEquals(" ", r1.toString()); } @Test public void testContains1() { } assertTrue(r1.contains(getPoint(x: 1,y:2))); @Test public void testContains() { } assertTrue(r1.contains(r2)); @Test public void testOverlapsWith1() { } } assertTrue(r1.overlapsWith(r2)); package hk.edu.polyu.comp.comp2021.assignment1. shape; public class XYRectangle { private Point topleft; private Point bottom Right; public Point getTopLeft() { return topLeft; } public Point getBottom Right() { return bottomRight; } public XYRectangle (Point p1, Point p2) { // Todo: complete the constructor } public String toString() { // Todo: complete the method return ""; } public int area() { // Todo: complete the method return 0; } public void rotateClockwise() { // Todo: complete the method return; } public void move(int deltax, int deltaY) { // Todo: complete the method } public boolean contains (Point p) { // Todo: complete the method return false; } public boolean contains (XYRectangle r) { // Todo: complete the method return false; } public boolean overlapsWith(XYRectangle r) { // Todo: complete the method return false; } class Point{ private int x; private int y; public Point (int x, int y) { set(x, y); } public int getX() { return x; } public int getY() { return y; } public void set (int x, int y) { this.x = x; this.y = y; } } public String toString() { } return "(" + getX() + "," + getY() + ")";
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
answer the question clearly You are building a flight-control system for which a convincing safety case must be made. Would you assign the tasks of safety requirements engineering, test case...
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
A woman is 5'6" and 150 lbs. pre-pregnancy. Calculate the healthy weight range (lowest to highest) you expect to see just prior to delivery. Include all math to show how you found the answer. A woman...
-
"Tax avoidance is discouraged by the courts and Congress." Is this statement true or false? Please explain.
-
Systolic blood pressure for a group of women is normally distributed, with a mean of 120 and a standard deviation of 12. Find the probability that a woman selected at random has blood pressure (a)...
-
What is meant by corporate governance and why is it important?
-
Carole Dahl is chief financial officer of the Phoenix Division of Dahl Corporation, a multinational company with three operating divisions. As part of the budgeting process, Dahl's staff is...
-
Research articles on Online Analytic Processing (OLAP) and Online Transaction Processing (OLTP). Next, compare and contrast the key similarities and differences between Online Analytical Processing...
-
A decreasing-cost industry has a long-run supply curve that is upward sloping. True b. False 10. Suppose firm X is a monopolist and is receiving positive economic profits. What prevents orbe firms...
-
Universal Auto is a large multinational corporation headquartered in the United States. For segment reporting purposes, the company is engaged in two businesses: production of motor vehicles and...
-
Forces with magnitudes of 180 newtons and 275 newtons act on a hook (see figure). The angle between the two forces is degrees.(a) When = 30, find the direction and magnitude of the resultant...
-
In a large group of corporate executives, 20 % have no college education, 10 % have exactly 2 years of college, 20 % have exactly 4 years, and 50 % have 6 years. A sample size of 2 (with replacement)...
-
A medical insurance survey found that more than 90 percent of the plans members are satisfied. Identify two kinds of survivor bias that may affect these results. Is the reported satisfaction rate...
-
Assume that Beck Consulting chooses to take advantage of current business opportunities and will need to grow to 100 members in the next 9 months in order to respond to the challenges. What changes...
-
a) A computer system has enough room to hold five programs in its main memory. These programs are idle waiting for I/O half the time. What fraction of the CPU time is wasted. b) A real-time system...
-
10m solution. If Ka(HA) = 10 then pOH of solution will be [Given : log4=0.6] (A) 6.7 (B) Greater than 6.7 & less than 7.0 (C) Greater 7.0 & less than 7.3 (D) Greater than 7.3
-
Mark each of the following true or false. ___ a. It is impossible to double any cube of constructible edge by compass and straightedge constructions. ___ b. It is impossible to double every cube of...
-
Let G be a finitely generated abelian group with identity 0. A finite set {b 1 , , b n }, where b i G, is a basis for G if {b 1 , , b n } generates G and n i=1 =1 m i b i = 0 if and only if...
-
Let G be an abelian group and let H and K be finite cyclic subgroups with |H| = r and |K| = s. a. Show that if r and s are relatively prime, then G contains a cyclic subgroup of order rs. b....
-
Why do you think this development occurred?
-
P. Topp is employed at a rate of 12 per hour. During the week to 18 May 2016 he worked his basic week of 40 hours. According to the requisite tables the income tax due on his wages was 46, and...
-
Write down what you think would be good definitions for the term 'wage' and the term 'salary'.
Study smarter with the SolutionInn App