estimationapp.java

来自「Produce a Java program to calculate the 」· Java 代码 · 共 72 行

JAVA
72
字号
import java.util.*;
class EstimationApp
{

	//----------------FIELDS------------------
	private static Scanner input = new
			Scanner(System.in);

	//---------------METHODS---------------
	public static void main(String[] args)
	{
		int selector = outputValue();
		double termValue, pi;

		processSelector(selector);
	}

	//----------------OUTPUT-----------------
	private static int outputValue()
	{
		int selector = 0;

		while (selector < 1 || selector > 2)
		{
			System.out.println("Please choose one of the methods below");
			System.out.println("======================================");
			System.out.println("1. FrancoisVieta");
			System.out.println("2. JohnWallis");
			System.out.println("Please input your Select Option:");

			selector = input.nextInt();
		}
		//---------------Return selsction------------
		return (selector);
	}

	private static void processSelector(int selector)
	{
		System.out.print("Please input a positive number ");
		int termNo = input.nextInt();
		Estimation newEstimation = new Estimation(termNo);

		switch (selector)
		{
			case 1:
				FrancoisVieta newFrancoisVieta = new FrancoisVieta(termNo);
				newFrancoisVieta.calc_pi();
					if (termNo > 0)
					{
						System.out.print("FrancoisVieta:" + newFrancoisVieta.calc_pi());
					}
					else
						System.out.print("Error, please check your input!");
					
				termNo = input.nextInt();
				break;

			case 2:
				JohnWallis newJohnWallis = new JohnWallis(termNo);
				newJohnWallis.calc_pi();
					if (termNo > 0)
					{
						System.out.print("JohnWallis:" + newJohnWallis.calc_pi());
					}
					else
						System.out.print("Error, please check your input!");
				
				termNo = input.nextInt();
				break;		
		}
	}
}

⌨️ 快捷键说明

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