【发布时间】:2014-03-02 06:57:46
【问题描述】:
我正在为我的计算机科学课做作业,但我被困在了这一部分。我应该为给定的 main 方法和实例变量编写构造函数。构造函数需要有一个 ArrayList 和一个 Array 作为参数,但我不完全确定如何。
说明及主要方法如下:
使用cmets和提供的代码完成构造函数
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();
}
}
我目前拥有的构造函数是这样的: 公共矩形统计(双 w,双 l) { 宽度 = w; 长度 = l; 面积=0; }
但我不确定它是否正确.. 帮助?
【问题讨论】:
-
你的构造函数在哪里?
-
嗯,这就是我要弄清楚的......我写下了我认为构造函数应该是什么,但我不太确定......
标签: java arrays arraylist parameters constructor