-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDequeuePopHandler.java
More file actions
51 lines (49 loc) · 1.6 KB
/
DequeuePopHandler.java
File metadata and controls
51 lines (49 loc) · 1.6 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
import javax.swing.JOptionPane;
/**
*This class defines two overloaded constructors, in order to match the overloaded constructors
*in 'GeneralHandler' class. And responsible to delete one element from the Stack/Queue
*/
public class DequeuePopHandler extends GeneralHandler{
/**DequeuePopHandler constructor, initializes a new DequeuePopHandler
*@param intQ the reference to a Queue of Integers
*/
public DequeuePopHandler(Queue<Integer> intQ){
super(intQ);
}
/**DequeuePopHandler constructor, initializes a new DequeuePopHandler
*@param intSt the reference to a Stack of Integers
*/
public DequeuePopHandler(Stack<Integer> intSt){
super(intSt);
}
@Override
/**This method implements the abstact method "processRequest",
*inherited from GeneralHandler class. This method Dequeue/Pop an item from
*the Queue/Stack respectively, and presents message to the user,
*if the examined Queue/Stack is empty, issues an appropriate message to the user
*/
public void processRequest(){
JOptionPane dialog = new JOptionPane();
String action=null,type=null;
int val=0;
if(intQ==null){
action="pop";
type="Stack";
if(intSt.isEmpty()){
dialog.showMessageDialog(null,"The "+type+" is Empty!!!!");
return;
}
else val = intSt.pop();
}
else {
action="dequeue";
type="Queue";
if(intQ.isEmpty()){
dialog.showMessageDialog(null,"The "+type+" is Empty!!!!"); //check about writing the same twice
return;
}
else val = intQ.dequeue();
}
dialog.showMessageDialog(null,"value "+action+" from "+ type +" is: "+ val);
}
}