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

📄 deviationtest.java

📁 PSP实践第一个练习
💻 JAVA
字号:
package psp0_1;

import java.io.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;

public class DeviationTest {

	public DeviationTest() {
		super();
		// TODO Auto-generated constructor stub
		caculator = new LinkedListCaculator();
	}
	
	
	public void run()
	{
		System.out.println("please enter a double number:");  //input the string 
		System.out.println("enter \"end\" to get the mean and deviation");
		System.out.println("Notice:the devation of no number will be 0 \n       and the devation of only one number will be 1");
		String str = null;
		
		while(true)
		{
			str = this.getString();
			
			if(str.equalsIgnoreCase("end"))
			{
				this.printResult();
				return;
			}else
			{
				try
				{
					double d = Double.parseDouble(str);
					caculator.addNum(d);
					continue;
					
				}catch(Exception e)
				{
					System.out.println("wrong format,enter enter a new double or \"end\"");
					continue;
				}
			}
		}
	}
	
	private String getString()
	{
		String str = null;
		
 		try
         {
  	        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            str = in.readLine();
         }catch(IOException e){};

         return str;
	}

	private void printResult(){
		
		NumberFormat numberForm = NumberFormat.getInstance();
		DecimalFormat df = (DecimalFormat)numberForm;
		df.setMaximumFractionDigits(2);
		
		
		System.out.println("the mean of the number is "+ df.format(caculator.getMean()));
		System.out.println("the deviation of the number is " + df.format(caculator.getDeviation()));
		
	}
	
	private SimpleCaculator caculator;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		DeviationTest test = new DeviationTest();
		
		test.run();
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -