Question
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;
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.add(5.2);
dblWidth.add(9.3);
double [ ] dblLength = {11.1, 4.7};
RectangleStats rectStats = new RectangleStats(dblWidth, dblLength);
rectStats.calcRectangleArea();
rectStats.printArea();
}
}
Please answer in Java
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started