The Class for a Rectangle is shown below. PlaneRectangle is a specialisation of Rectangle with fields that define the location of the centre of the rectangle. Write Java Classes that are implementations of the Rectangle Class and of the PlaneRectangle Class.
Now add methods to the Java PlaneRectangle Class that:
a. enable the location of an instance of PlaneRectangle to be moved by a specified distance (expressed as a change in the x-coordinate, and a change in the y-coordinate).
b. Enable a check to be made that a given point lies inside or outside the rectangle.
c. Enable a check to be made that another instance of PlaneRectangle lies completely within the current instance.
These classes come with default "constructor methods". Write the Java code for new constructors for the Rectangle Class that enable:
a. An instance of the Rectangle Class to be created with a default length of 1.0. and a default width of 1.0.
b. An instance of the Rectangle Class can be created with user specified values for the length and width.
Now add constructors to the PlaneRectangle Class to enable:
a. An instance of the PlaneRectangle Class to be created with the above default length and width, and located at the origin by default.
b. An instance of the PlaneRectangle Class to be created with user specified values for the length, width and location.
Write a Java application that enables the user to specify the length, width and location of two instances of a PlaneRectangle and check whether the first lies completely within the second.© BrainMass Inc. brainmass.com March 4, 2021, 5:45 pm ad1c9bdddf
"These classes come with default "constructor methods"."
Every class has at least one constructor. If you do not write a constructor, the Java programming language provides one for you. This constructor takes no arguments and has an empty body.
The default constructor doesn't do anything. So, if you want to perform some initialization, you will have to write some constructors for your class.
"Write the Java code for new constructors for the Rectangle Class that enable:
a. An instance of the Rectangle Class to be created with a default length of 1.0. and a default width of 1.0."
Constructors are identified by the two following rules:
The method name must exactly match the classname.
There must not ...
In this solution you will learn about Java constructors, and how to use them to create an small application. In particular this example shows the use of a constructor in creating a shape object called Rectangle. Note, you can use the same concept for other geometric shapes.