Java Programming Language Assignment Must Write Class Rectangle Tester Rectangletest Recta Q43903788
In Java programming language.
For this assignment, you must write a class Rectangle and atester RectangleTest. The Rectangle class should have only thefollowing public methods (you can add other non-publicmethods):
-
Write a constructor that creates a rectangle using the x, ycoordinates of its lower left corner, its width and its height inthat order. Creating a rectangle with non-positive width or heightshould not be allowed, although x and y are allowed to benegative.
-
Write a method overlap(Rectangle other). This method shouldreturn true if this rectangle overlaps with other, false otherwise.Rectangles that touch each other are not considered to beoverlapping.
-
Write a method intersect(Rectangle other). This method shouldreturn a Rectangle object that represents the overlap of the tworectangles. If no intersection exists, it should throw aNoSuchElementException with a helpful message.
-
Write a method union(Rectangle other). This method returns aRectangle object that represents the union of this rectangle andthe other rectangle. The union is the smallest rectangle thatcontains both rectangles. Note that unlike the intersection, theunion always exists.
-
Write a method toString that returns a String. The string shouldbe formatted exactly as: “x:2, y:3, w:4, h:5” without the quotationmarks and replacing the numbers with the actual attributes of theobject.
There exists a class called Rectangle in Java already. You arenot allowed to use this class in any way! Make sure that you arenot accidentally importing it!
A few suggestions about tests:
-
You need more than one tests for overlap, because there can beseveral kinds of overlap. Think about it!
-
Write as many tests as you can think of. But you do not need toconflate many tests into one method: for example, you can writeseveral different methods to test just overlap provided you isolatethe objective of each test.
Expert Answer
Answer to In Java programming language. For this assignment, you must write a class Rectangle and a tester RectangleTest. The Rect…
OR