Hey all, this seems easy enough, but I\'m getting errors while I try to compile
ID: 3637336 • Letter: H
Question
Hey all, this seems easy enough, but I'm getting errors while I try to compile my code.Here's the set up:
*************************************
The Rectangle class in the standard Java API package java.awt is designed to logically represent a rectangle by simply storing information about a given rectangle's position on a graph (its x-y coordinates) as well as its dimensions (width and height). If you call one of the System.out print methods on a Rectangle object variable, the x-coordinate, y-coordinate, width and height of the rectangle logical representation is displayed.
//The following program creates a new Rectangle and prints its information.
import java.awt.Rectangle;
public class RectangleTester
{
public static void main(String[] args)
{
Rectangle r1 = new Rectangle(0, 0, 100, 50);
System.out.println(r1);
}
}
Add code to the program above to create a second rectangle with the same values (x, y, width, and height) as the first Rectangle (see instructions below on what constructor to use). Print the second rectangle as per the code provided for the first rectangle. Then apply the grow method to the second rectangle variable (grow(10, 20)) and, after the grow method, print both rectangles again. This will give you a before and after view of the attribute values associated with each of the two rectangle object variables. For more information on the grow method, look at the API documentation.
Use the following Rectangle constructor to create the second rectangle:
public Rectangle(Rectangle r)
*******************************
I've tried playing around with the constructor public Rectangle(Rectangle r) but I'm not able to get it to work. I can do it without the constructor, but the directions specifically say to use it. I'd appreciate any help.
Thanks!!
Explanation / Answer
Rectangle r2 = new Rectangle(r1); try this it should work.