Guest User

Untitled

a guest
Apr 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. public class AddNumbers implements Chain{
  2.  
  3. private Chain nextInChain;
  4.  
  5. // Defines the next Object to receive the
  6. // data if this one can't use it
  7.  
  8. public void setNextChain(Chain nextChain) {
  9.  
  10. nextInChain = nextChain;
  11.  
  12. }
  13.  
  14. // Tries to calculate the data, or passes it
  15. // to the Object defined in method setNextChain()
  16.  
  17. public void calculate(Numbers request) {
  18.  
  19. if(request.getCalcWanted() == "add"){
  20.  
  21. System.out.print(request.getNumber1() + " + " + request.getNumber2() + " = "+
  22. (request.getNumber1()+request.getNumber2()));
  23.  
  24. } else {
  25.  
  26. nextInChain.calculate(request);
  27.  
  28. }
  29.  
  30. }
  31. }
Add Comment
Please, Sign In to add comment