-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiply.java
52 lines (43 loc) · 1.35 KB
/
Multiply.java
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
package proj4;
/**
* MULTIPLY CLASS
* An operator that is handle a certain way to convert from infix to postfix notation
* @author Jordan An
* @version 05/28/2020
*/
public class Multiply implements Operator{
private final int PRECEDENCE = 2;
/** Processes the current token. Since every token will handle
* itself in its own way, handling may involve pushing or
* popping from the given stack and/or appending more tokens
* to the output string.
*
* @param s the Stack the token uses, if necessary, when processing itself.
* @return String to be appended to the output
*/
public String handle(Stack<Token> s){
Token topStack = s.peek();
String ans = "";
while (!s.isEmpty() && !(topStack instanceof LeftParen) && ((Operator) topStack).getPrecedence() >= this.getPrecedence() ){
Token tempToken = s.pop();
ans += tempToken.toString();
topStack = s.peek();
}
s.push(this);
return ans;
}
/** Returns the token as a printable String
*
* @return the String version of the token.
*/
public String toString(){
return "*";
}
/**
* Return the value of operator's precedence
* @return the operator precedence
*/
public int getPrecedence() {
return PRECEDENCE;
}
}