📄 calculator.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 + -