Question: Rectangle.java: -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- In this Minilab, you are given a class called Rectangle, which describes a 2-dimensional Rectangle. You should. 1- Look at the Rectangle code

 Rectangle.java: -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- In this Minilab, you are given a class called

Rectangle, which describes a 2-dimensional Rectangle. You should. 1- Look at the

Rectangle.java:

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Rectangle code and be familiar with it. It has: Data: that stores

width and height (as ints). Constructors: - default constructor which receives nothing

In this Minilab, you are given a class called Rectangle, which describes a 2-dimensional Rectangle. You should. 1- Look at the Rectangle code and be familiar with it. It has: Data: that stores width and height (as ints). Constructors: - default constructor which receives nothing and always sets the width and height to 5 and 2. parameterized constructor which receives 2 ints (width, then height) and sets the width and height to what is received Methods: toString() - returns its representation as a String. Dimensions are included as width, then height. getWidth() - returns the width getPerimeter() - returns its perimeter getSumOfDimensions returns the width + height 2- You are to create another class called Box, which will be defined as a subclass of Rectangle. It should have the following: Data: It should inherit 2 dimensions (so you will have to change how Rectangle's data is declared) and then declare a 3rd dimension which will be the depth. All dimensions will be ints. Constructors: There should be 2 constructors It should have a default constructor that sets its 3 dimensions (width, height, and depth) to 5, 2, and 6. (Note that Rectangle has a default constructor that also sets the first 2 dimensions to 5 and 2 so you can call super() to set the first 2 dimensions if you want). It should also have a parameterized constructor that receives 3 ints (width, then height, then depth) and sets the data to whatever is received. The parameterized constructor should check to see if any of the dimensions are negative - if so, it should throw new IllegalArgumentException"'); (Note that Rectangle has a parameterized constructor that also sets the first 2 dimensions to what is received so you can call super(theWidth, theHeight) to check and set the first 2 dimensions if you want. Methods: there should be 5 methods declared: toString() method that will return a String that describes it: For example, if the width height/depth are 4,5,6, then the toStringo will return Box: 4x5x6" (Optional since Rectangle's toStringo will return automatically put in the class name and then 2 dimensions, you could (if you want), write Box's toString by returning super.toString and then put in the third dimension. getPerimeter() method that will just throw new IllegalStateException(your String). This is necessary since Box will inherit a getPerimeter() method from Rectangle, but it should never be called since Box does not have a perimeter! getWidth() method that will receive nothing and return the width. Actually...you do not even have to code this since Rectangle already as a getWidth that will be inherited! getSumOfDimensions method which will receive nothing and return the sum of all 3 dimensions. If you want, you could use Rectangles getSumOfDimensions() method in your calculation by calling super.getSumOfDimensions and then just adding in the depth (or you could specifically add up all 3 dimensions). getSurfaceArea() method which will return its surface area as an int). /* This class will represent a rectangle. It has 2 dimensions, which are called width and height (so it does not matter which is larger). */ public class Rectangle { //------- data protected int width; protected int height; //-------- constructors //default constructor public Rectangle() { this.width = 5; this.height = 2; } 1/parameterized constructor public Rectangle(int theWidth, int theHeight) { if (thewidth

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!