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

📄 estimationapp.java

📁 Produce a Java program to calculate the value of π in two different methods proposed by Francois Vie
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -