-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuxiliaryCommand.java
More file actions
51 lines (41 loc) · 1.16 KB
/
Copy pathAuxiliaryCommand.java
File metadata and controls
51 lines (41 loc) · 1.16 KB
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
package com.company;
import com.company.exceptions.EmptyStackException;
import java.util.*;
public class AuxiliaryCommand {
private final Map<String, Double> value = new HashMap<>();
private final Stack<Double> stack = new Stack<>();
public void push(Double value){
stack.push(value);
}
public Double pop(){
try {
Double temp = stack.pop();
return temp;
} catch (NoSuchElementException e) {
throw new EmptyStackException("Stack is empty");
}
}
public Double peek(){
Double temp = stack.lastElement();
if (temp == null) {
throw new EmptyStackException("stack is empty");
} else {
return temp;
}
}
public void add(String name, Double temp){
value.put(name, temp);
}
public Double get(String name){
return value.get(name);
}
public List<Double> getStack(){
return Collections.unmodifiableList(stack);
}
public int size(){
return stack.size();
}
public boolean empty(){
return stack.empty();
}
}