forked from rick2785/JavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddNumbers.java
More file actions
31 lines (18 loc) · 624 Bytes
/
AddNumbers.java
File metadata and controls
31 lines (18 loc) · 624 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
public class AddNumbers implements Chain{
private Chain nextInChain;
// Defines the next Object to receive the
// data if this one can't use it
public void setNextChain(Chain nextChain) {
nextInChain = nextChain;
}
// Tries to calculate the data, or passes it
// to the Object defined in method setNextChain()
public void calculate(Numbers request) {
if(request.getCalcWanted() == "add"){
System.out.print(request.getNumber1() + " + " + request.getNumber2() + " = "+
(request.getNumber1()+request.getNumber2()));
} else {
nextInChain.calculate(request);
}
}
}