⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linkedlistcaculator.java

📁 PSP实践第一个练习
💻 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 + -