Answered step by step
Verified Expert Solution
Question
1 Approved Answer
java problem needs help 1. Familiarize yourself with Java's Rectangle class in the java.awt package 2. Write and document (Javadoc-format) a NicerRectangle class that extends
java problem needs help
1. Familiarize yourself with Java's Rectangle class in the java.awt package 2. Write and document (Javadoc-format) a NicerRectangle class that extends the Rectangle class o Do not add any instance variables o Create 3 constructors. Each should make an appropriate call to another constructor either in the Rectangle class or in the NicerRectangle class i. A 4-parameter constructor that specifies the x, y, width, and height, in that order A 2-parameter constructor that specifies the x and y values, and sets the width and height to 1 A no-parameter constructor that sets the x and y to zero, and the width and height to 1 i. o Create getPerimeter and getArea methods that return the perimeter and area of the rectangle as int values. This method should call on the appropriate getters from the Rectangle class. Do not rely on the public instance variables o Create a containsPoint method. The method has one Point parameter and returns true if the corresponding point is inside but not on the rectangle and return false otherwise o Create a containsSegment method. The method has two Point parameters representing the endpoints of a line segment. Return true if the corresponding line segment lies entirely inside but not on the rectangle, and return false otherwise Create a no-parameter void mutator named doublesize that doubles the length and width of the rectangle. The x- and y-coordinates should not change Override the tostring method so that the returned string contains all the information from the Rectangle toString, along with the perimeter and area of the NicerRectangle. See the sample output on the next page o o 3. Do not submit a separate tester class. Instead, write the standard main) method inside ass. In it, ask the user for a number of rectangles to be created. Then, create an array or ArrayList of randomly generated NicerRectangle objects (x, y, width, and height should all be random values in the range 1 to 20 inclusive). Print all of these objects, then grow all of the objects using your doublesize method and then print them again. Finally, ask the user for the x- and y-coordinates of two points, and print a list of only the rectangles that contain the first point, all the rectangles that contain the second point, and all the rectangles that contain the segment formed by using those two points as endpoints. 4. Zip your one source code file, NicerRectangle.java, and upload the zip file to Canvas Here's a sample run of my tester (the main) method is inside the NicerRectangle class) How many rectangles? 4 4 random rectangles. . . NicerRectangle[x=6,y=7,width-4,height=5] NicerRectangle[x=5,y=8 , width-2 , height-6] NicerRectangle[x=6,y= 9 , width=9,height=9] NicerRectangle[x-1,y-3, width-7, height-4] Area-20, Perimeter=18 Area-12, Perimeter=16 Area-81, Perimeter=36 Area 28, Perimeter-22 after doubling NicerRectangle[x=6,y=7,width-8,height=10] Area-80, Perimeter=36 NicerRectangle[x=5,y=8 , width-4,height=12] Area-48, Perimeter=32 NicerRectangle[x=6,y= 9 , width-18,height=18] Area-324, Perimeter#72 NicerRectangle[x=1,y=3,width-14,height=8] Area-112, Perimeter=44 Enter x- and y-coordinates ior start: 3 5 Enter X- and y-coorainatas Tor endl: Here are the rectangles that contain point 3 5: NicerRectangle[x=1,y=3,width-14,height=8] Area-112, Perimeter=44 Here are the rectangles that contain point 78: NicerRectangle[x=6,y=7,width-8,height=10] Area-80, Perimeter=36 NicerRectangle[x=1,y=3,width-14,height=8] Area-112, Perimeter=44 Here are the rectangles that contain the segment from 3 5 to 78: NicerRectangle[x=1,y=3,width-14,height=8] Area-112, Perimeter=44Step 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