I'm doing an assignment for my Computer Science class, but I got stuck in this one part. I am supposed to code the constructor for the given main method and instance variables. The constructor needs to have an ArrayList and an Array as parameters, but I'm not entirely sure how to.
The instructions and main method is as follows:
Use the comments and the code provided to complete the constructor
import java.util.ArrayList;
class RectangleStats
{
//instance variables go 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 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();
}
}
The constructor I currently have is this: public RectangleStats(double w, double l) { width = w; length = l; area = 0; }
but im not sure if its right or not.. Help?