我正在为我的计算机科学类做一个任务,但是我陷入了这一部分。我应该编写给定的主要方法和实例变量的构造函数。构造函数需要有一个ArrayList和一个Array作为参数,但我不完全确定如何。ArrayList和Array作为构造函数的参数
的指导和主要方法如下:
使用提供完成构造
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();
}
}
我目前拥有的构造函数的注释和代码是这样的: 公共RectangleStats (双w,双l) 宽度= w; length = 1; area = 0; }
但我不知道如果它的权利或不..帮助?
你的构造函数在哪里? – Kakarot
这就是我要弄清楚..我写下了我认为的构造应该是,但即时通讯不太确定.. – user3164890