?? linkedlistcaculator.java
字號:
package psp0_1;
import java.util.LinkedList;
/**
* concrete caculator,using LinkedList to hold the data
* @author qian
* 2006 9/12
*/
public class LinkedListCaculator implements SimpleCaculator{
public LinkedListCaculator() {
super();
// TODO Auto-generated constructor stub
list = new LinkedList();
}
public void addNum(double d)
{
list.add(new Double(d));
}
public void clearFigure()
{
list.clear();
}
public double getMean()
{
double sum = 0;
int length = 0;
double result = 0;
for(int i = 0; i < list.size();i++)
{
Double d =(Double)list.get(i);
sum = sum + d.doubleValue();
length ++;
}
if(length == 0)
{
result = 0;
}else
{
result = sum/length;
}
return result;
}
/**
* no data will return 0 and 1 data will return 0
*/
public double getDeviation()
{
int length = list.size();
double sum = 0;
double mean = this.getMean();
double result = 0;
for(int i = 0; i < list.size() ; i++)
{
Double d =(Double)list.get(i);
sum = sum + (d.doubleValue()-mean)*(d.doubleValue()-mean);
}
if(length <= 1)
{
result = 0;
}else
{
result = Math.sqrt(sum/(length - 1));
}
return result;
}
private LinkedList list;//the list to hold the data
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -