-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCalculator.java
More file actions
43 lines (38 loc) · 809 Bytes
/
Calculator.java
File metadata and controls
43 lines (38 loc) · 809 Bytes
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
/*
* #C1 Calculator (7pt)
* implement a calculator that takes a char[] and returns a value
*
* Should handle +, /, -, *, e, and m
* (e for exponentiation, m for modulo)
*
* Should handle unlimited correctly matched parenthesis
*
* example input:
*
* input: (3+4)
* value: 7.0
*
* input: ((4+6)*2)
* value: 20.0
*
*
*/
public class Calculator {
public static void main(String[] args) {
System.out.println("calculator " + (calcTest()?"Passed":"Failed"));
}
/*
* note: you should test MUCH more thoroughly than this
*/
static boolean calcTest() {
if(calc("(3+4)".toCharArray())!=7.0) return false;
if(calc("((4+6)*2)".toCharArray())!=20.0) return false;
return true;
}
/*
* complete
*/
static double calc(char[] a) {
throw new NotImplemented();
}
}