-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassessment-coding-description.txt
65 lines (51 loc) · 2.22 KB
/
assessment-coding-description.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Programming Exercise: Natural Language Calculator Problem
Write a text-based console application to perform simple natural language calculations.
For example, if the user enters the text ‘two plus four’ the program would output the value ‘6’.
The program should be implemented in Java and please avoid using libraries or scripting engines, for
this exercise we want to see how you would implement the solution yourself.
We would expect implementation to take no more than 4 hours.
Specification
Supported Input Values
- The supported input values are the whole numbers between zero and nine inclusive.
- Input values must be expressed as text, e.g. ‘one’, ‘five’, etc
- Input values are not case-sensitive. Both ‘two and ‘TWO’ are equally valid.
Supported Arithmetic Operators
- The supported arithmetic operators and the permitted natural language aliases for these
commands are detailed in the table below.
- Aliases are not case-sensitive. Both ‘add’ and ‘ADD’ are equally valid.
Operator Permitted Aliases
Add (+) -> add, plus
Subtract (-) -> subtract, minus, less
Multiply (*) -> multiply-by, times
Divide (/) -> divide-by, over
Operation Chaining
- Any number of operations may be chained together
o For example, these calculations are all valid
- ‘one plus two’
- ‘seven times eight minus nine’
- ‘four times five subtract six over one plus nine’
Operator Precedence
- When two or more operations are chained together, any multiply or divide operation must take
precedence over any add or subtract operation, similar to how a real calculator works.
o For example, the calculation ‘one plus two times three’ will give the result ‘7’ not ‘9’.
- The examples section contains further examples to illustrates operator precedence.
- Note that there is no requirement to support the use of brackets to alter operator precedence.
Examples
Please enter a calculation:
nine over eight plus four times two divide-by three
Result: 3.79
Please enter a calculation:
one plus two
Result: 3
Please enter a calculation:
one plus two times three
Result: 7
Please enter a calculation:
nine minus three times seven
Result: -12
Please enter a calculation:
four minus eight plus six times nine
Result: 50
Please enter a calculation:
seven over nine plus one
Result: 1.78