Purchase Solution

How to write Java code for a Rectangle

Not what you're looking for?

Ask Custom Question

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.

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.
(Figure 1 in the attachment)
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.

Purchase this Solution

Solution Summary

Constructors and explanation for Rectangle Class

Solution Preview

"The Class for a Rectangle is shown below"
<br>
<br>As the class is NOT shown in the question, it has to be assumed from the question. The following suggestion is made from a generic assumption based on a rectangle class.
<br>
<br>"These classes come with default "constructor methods"."
<br>
<br>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.
<br>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.
<br>
<br>"Write the Java code for new constructors for the Rectangle Class that enable:
<br>a. An instance of the Rectangle Class to be created with a default length of 1.0. and a ...

Purchase this Solution


Free BrainMass Quizzes
Javscript Basics

Quiz on basics of javascript programming language.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.