Question: 5. Examine the following starter code. Use the comments and the code provided to complete the constructor and two methods in the RectangleStats class. import

5.

Examine the following starter code. Use the comments and the code provided to complete the constructor and two methods in the RectangleStats class.

import java.util.ArrayList;

class RectangleStats

{

// Private instance variables

// width is an ArrayList which will contain decimal values, length is an array which will contain decimal

// values, and area is an array which will contain integer values.

//code goes here for instance variables goes here

//The constructor for the RectangleStats class takes an ArrayList and an array as parameters for

// width and length, respectively.

// code for constructor goes here

// The calcRectangleArea() method calculates the area of rectangles using the length and width

// assigned to the private instance variables and assigns the results to the area array of type int.

// This method does not return anything.

// code for the calcRectangleArea() method goes here

// The printArea() method prints the values assigned to the area array using the most appropriate

// type of loop. This method does not return anything.

// code for the printArea() method goes here

}

// The RectangleStatsTesterClass assigns the width of two rectangles to an ArrayList and assigns the

// length of two rectangles to an array. The calcRectangleArea() and printArea() methods are invoked to

// calculate and print the area of the two rectangles.

public class RectangleStatsTesterClass

{

public static void main(String[] args)

{

ArrayList dblWidth = new ArrayList();

dblWidth.add(5.2);

dblWidth.add(9.3);

double [ ] dblLength = {11.1, 4.7};

RectangleStats rectStats = new RectangleStats(dblWidth, dblLength);

rectStats.calcRectangleArea();

rectStats.printArea();

}

}

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!