Computer Science Homework Solutions
Problem
#9763

Using constructor to create Rectangle and PlaneRectangle classes

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.

Attached file(s):
Attachments
Rectangle Java Problem.doc  View File

Attachment Content Summary (Note: view attachment at the above link before purchasing. Actual attachment content may vary slightly from that shown below.)

Rectangle Java Problem.doc
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:

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).

Enable a check to be made that a given point lies inside or outside the
rectangle.

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:

An instance of the Rectangle Class to be created with a default length
of 1.0. and a default width of 1.0.

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:

An instance of the PlaneRectangle Class to be created with the above
default length and width, and located at the origin by default.

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.

Rectangle

length

width

area

circumference

Solution Summary

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.

Solution
What is this?
By OTA - Overall OTA Rating
Purchase Cost Now
$2.19 CAD
Included in Download
  • Plain text response
$2.19 Instant Download
Add to Cart
Why you can trust BrainMass.com
  • Your Information is Secure
  • Best Online Academic Help Service
  • Students find real academic Success
Related Solutions
  • Java code for rectangle - Having problems with part of question beginning: "These classes come with default "constructor methods". Write the Java code for .." through to and including last question from the question below. ...
  • C++ Programming Control Structures I - Write a program that prompts the user to input the x-y coordinate of a point in a Cartesian plane. The program should then output a message indicating whether the point is the orgin, is located on th ...
  • Write a constructor - Can someone write a constructor method for the class "Dog" that uses the "this reference" and explain what it does?
  • Write an interactive Java program that illustrates the use of methods, constructors, loops and arrays. - Write an interactive Java program that illustrates the use of methods, constructors, loops and arrays. Your Program will do the following: 1. Ask the user for a String input of letters, i.e., Oh ...
  • Classes and Enumerators - Use the type Date (consisting of a month name, day number, and a year number) to develop a class Event to model events scheduled for specified dates. use this class in a program that reads several ev ...
Browse