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

📄 calculator.java

📁 Java编写的表达式计算器, 即可以像我们书写表达式那样直接输入计算表达式, 程序自动进行运算, 支持加减乘除幂运算以及判断表达式如A?B C, 程序包含完整的Document和测试运行环境
💻 JAVA
字号:
package parser;

/**
 * @Copyright(C) 2008 Software Engineering Laboratory (SELAB), Department of Computer 
 * Science, SUN YAT-SEN UNIVERSITY. All rights reserved.
**/

import java.io.*;
import exceptions.*;
/**
 * Main program of the expression based calculator ExprEval
 * 
 * @author [PENDING zouhao]
 * @version 1.00 (Last update: [PENDING the last update])
**/
public class Calculator
{
	/**
	 * The main program of the parser. You should substitute the body of this method 
	 * with your experiment result. 
	 * 
	 * @param expression  user input to the calculator from GUI. 
	 * @return  if the expression is well-formed, return the evaluation result of it. 
	 * @throws ExpressionException  if the expression has error, a corresponding 
	 *                              exception will be raised. 
	**/
	public double calculate(String expression) throws ExpressionException
	{
		Parser parser = new Parser(expression);
		parser.parsing();
		double result = parser.getresult();
		return result;
	}
	public static void main(String[] args) throws 
                Exception
        {
		System.out.println("Input an expression to calculator:");
		BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
		//String temp = keyboard.readLine();
		Parser parser = new Parser("min(2.5)");
		parser.parsing(); 
		System.out.println(parser.getresult());
		System.out.println("\nEnd of program.");
	}
}

⌨️ 快捷键说明

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