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...
-
Describe the business purpose, step-transaction, and substance-over-form doctrines. What types of tax planning strategies may these doctrines inhibit?
-
Write a paper on Action Research including introduction and methodology. What you plan to accomplish and why, include an overview of the situation or organization and what the situation/problem is...
-
A 6061-T6 aluminum alloy solid circular rod of length \(4 \mathrm{~m}\) is pinned at one end while fixed at the other end. If it is subjected to an axial load of \(15 \mathrm{kN}\) and F.S. \(=2\)...
-
Patrick Corporation acquired 100 percent of OBrien Companys outstanding common stock on January 1, for $550,000 in cash. OBrien reported net assets with a carrying value of $350,000 at that time....
-
On 1 January 20x3, APL granted each of the 50 team leaders 2,000 share options, under which, they can elect to receive 2,000 shares or a cash payment equivalent to the value of 2,000 shares on 31...
-
On June 1, 2021, Meghan purchased a $10,000 corporate bond at par value. She purchased the bond in between interest dates, as the bond pays annual interest of 5% on September 1 of each year. At the...
-
The lifetime of a light bulb in a certain application is normally distributed with mean \(\mu=1400\) hours and standard deviation \(\sigma=200\) hours. a. What is the probability that a light bulb...
-
Purse Corporation owns 70 percent of Scarf Companys voting shares. On January 1, 20X3, Scarf sold bonds with a par value of $600,000 at 98. Purse purchased $400,000 par value of the bonds; the...
-
Pistol Corporation purchased 100 percent ownership of Scope Products on January 1, 20X6, for $56,000, at which time Scope Products reported retained earnings of $10,000 and capital stock outstanding...
-
In Problems 47-56, decide whether you would use a permutation, a combination, or neither. Next, write the solution using permutation notation or combination notation, if possible, and, finally,...
-
In Problems 47-56, decide whether you would use a permutation, a combination, or neither. Next, write the solution using permutation notation or combination notation, if possible, and, finally,...
-
Let F = (, sin* x, cos x). Calculate curl(F). curl(F) =
-
Assessing simultaneous changes in CVP relationships Braun Corporation sells hammocks; variable costs are $75 each, and the hammocks are sold for $125 each. Braun incurs $240,000 of fixed operating...
-
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....
-
Dry, compressed air at \(T_{m, i}=75^{\circ} \mathrm{C}, p=10 \mathrm{~atm}\), with a mass flow rate of \(\dot{m}=0.001 \mathrm{~kg} / \mathrm{s}\), enters a \(30-\mathrm{mm}-\) diameter, 5 -m-long...
-
Heated air required for a food-drying process is generated by passing ambient air at \(20^{\circ} \mathrm{C}\) through long, circular tubes \((D=50 \mathrm{~mm}, L=5 \mathrm{~m}\) ) housed in a steam...
-
Liquid mercury at \(0.25 \mathrm{~kg} / \mathrm{s}\) is to be heated from 325 to \(375 \mathrm{~K}\) by passing it through a \(25-\mathrm{mm}\)-diameter tube whose surface is maintained at \(400...
Study smarter with the SolutionInn App