This test is designed to test your skills, and style in the Java programming language. The test
should be done in Java 5. There are only two requirements for you solution to this test: 1. it must
work as described 2. we must be able to compile it. Since this test is designed to test you skills and
knowledge in the Java programming language, make sure that you apply good coding pratices and
object oriented design to your solution. The solution must be sent to [email protected]. The
result file must contain the source code of your solution, as well as a readme file explaining how to
run it. Include the detailed steps required to compile your solution in the readme file (this includes
the javac command, the libraries to import etc...).
Good Luck!
Problem : Calculator application
Write a command line application that takes a mathematical expression as input and prints
the result to the console.
The mathematical expression should be read from a file. The expression can use integer
numbers only (but the result can be a floating number), and the only supported operators are +, -, *,
/. The expression can use parentesis "(" and ")" to group operations. The * and / operators have the
priority on the + and – operators.
Sample input file:
2 + 3 * (4+5) – 4/5
Sample console output:
2 + 3 * (4+5) – 4/5 = 28.2
Typical application usage:
java -jar calc.jar input.txt
The exact EBNF grammar for the acceptable input expressions is the following
Expression EBNF grammar:
expression = term (operator expression)?
term = number | '(' expression ')'
number = (('-')? non_zero_number (non_zero_number | '0')*) | '0'
non_zero_number = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
operator = '*' | '/' | '+' | '-'
Feel free to transform this grammar to an equivalent one if you feel the need to. If you do,
please include the modified grammar in your classes' documentation.
should be done in Java 5. There are only two requirements for you solution to this test: 1. it must
work as described 2. we must be able to compile it. Since this test is designed to test you skills and
knowledge in the Java programming language, make sure that you apply good coding pratices and
object oriented design to your solution. The solution must be sent to [email protected]. The
result file must contain the source code of your solution, as well as a readme file explaining how to
run it. Include the detailed steps required to compile your solution in the readme file (this includes
the javac command, the libraries to import etc...).
Good Luck!
Problem : Calculator application
Write a command line application that takes a mathematical expression as input and prints
the result to the console.
The mathematical expression should be read from a file. The expression can use integer
numbers only (but the result can be a floating number), and the only supported operators are +, -, *,
/. The expression can use parentesis "(" and ")" to group operations. The * and / operators have the
priority on the + and – operators.
Sample input file:
2 + 3 * (4+5) – 4/5
Sample console output:
2 + 3 * (4+5) – 4/5 = 28.2
Typical application usage:
java -jar calc.jar input.txt
The exact EBNF grammar for the acceptable input expressions is the following
Expression EBNF grammar:
expression = term (operator expression)?
term = number | '(' expression ')'
number = (('-')? non_zero_number (non_zero_number | '0')*) | '0'
non_zero_number = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
operator = '*' | '/' | '+' | '-'
Feel free to transform this grammar to an equivalent one if you feel the need to. If you do,
please include the modified grammar in your classes' documentation.
1。它必须能按要求运行
2。我们必须能编译它因为本测试是为了测试您在JAVA语言领域的技巧和知识,请务必在答案中使用好的代码practices(不知道这个词如何意译,实践?请楼下补充)和面向对象设计。请将答案发送到 [email protected] ,请附上您的程序源代码,以及一个readme文件,里面说明如何使用您的程序和编译程序的详细步骤(包括JAVAC命令,编译需要导入的包等等)。祝好运!题目: 计算应用。
输入一条数学表达式的命令,程序可以输出结果。该表达式可以从一个文件中读取,并且只能使用整数(但是结果可以使用浮点数),并且只支持下面几个运算符:+ - * / 可以使用小括号"(",")"来确定优先关系,*, /运算优先于+ ,- 运算。输入示例:
2 + 3 * (4+5) – 4/5
输出的结果示例:
2 + 3 * (4+5) – 4/5 = 28.2典型的用法:
java -jar calc.jar input.txt输入文件中表达式的精确的EBNF文法是:(译注:扩展的巴科斯-诺尔范式 Extended Backus-Naur Form,EBNF )
expression = term (operator expression)?
term = number | '(' expression ')'
number = (('-')? non_zero_number (non_zero_number | '0')*) | '0'
non_zero_number = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
operator = '*' | '/' | '+' | '-'需要的话您完全可以把上面的语法转换成等价的表达式,如果您做了转换,那么请在您的程序中附加转换后的语法。
不理解这个,还以为是个正则表达式呢。
都是废话来的。出考题的人为了卖弄自己的知识罢了。楼主按照小学的数学知识来弄就可以了。
大家注意看这个:
java -jar calc.jar input.txt
其实就是读入数据做计算,用逆波兰表达式,这个赵数据结构
怎么感觉这个题是对应届毕业生的呢?
几年前考程序员的时候学过了
忘了