如何创建新的DataSet?

时间:2013-12-07 14:50:51

标签: java arrays copy

所以我给这个赋值来编写一个做一些数字计算的类,客户端将一个随机双数组数组传递给Dataset。一切都取决于我是否正确地完成了该计划的这一部分。但说实话,我对这里做什么一无所知。

//Instance Data
private double[] data;

 //Constructor: Create a new DataSet
 // Parameter : data points to be included into this DataSet
 // Exception : the number of data points must be at least 2

public DataSet(double[] data)
{  


}

1 个答案:

答案 0 :(得分:0)

private double[] data;  

//As you throw a exception inside your method (constructor in this case)
//you need to declare the 'throws Exception' clause, so you have to 
//catch this exception when you create a new instance of DataSet.
public DataSet(double[] _data) throws Exception
{  
   //Your comment says 'the number of data points must be at least 2'
   //you accomplish this by checking its size.
   if(_data.length < 2) {
       //As it say exception I assume in this case you want to throw a exception
       //you accomplish this like the following           
       throw new Exception("the number of data points must be at least 2");
   }
   //"Save the parameter into the instance variable"
   //It's pretty clear to me what "t0mppa" said. Read again please...
   this.data = _data;
}