1 16 package org.apache.cocoon.components.flow.java.test; 17 18 import org.apache.cocoon.components.flow.java.*; 19 20 public class CalculatorFlow extends AbstractContinuable { 21 22 public void run() { 23 24 float a, b; 25 String op; 26 String uri = "page/"; 27 28 sendPageAndWait(uri + "getNumberA"); 29 a = Float.parseFloat(getRequest().getParameter("a")); 30 System.out.println("a=" + a); 31 32 sendPageAndWait(uri + "getNumberB", new VarMap().add("a", a)); 33 b = Float.parseFloat(getRequest().getParameter("b")); 34 System.out.println("b=" + b); 35 36 sendPageAndWait(uri + "getOperator", new VarMap().add("a", a).add("b", b)); 37 op = getRequest().getParameter("operator"); 38 System.out.println("operator=" + op); 39 40 if ("plus".equals(op)) { 41 System.out.println("result=" + (a + b)); 42 sendPage(uri + "displayResult", new VarMap().add("a", a).add("b", b).add("operator", op).add("result", a + b)); 43 } 44 else if ("minus".equals(op)) { 45 System.out.println("result=" + (a - b)); 46 sendPage(uri + "displayResult", new VarMap().add("a", a).add("b", b).add("operator", op).add("result", a - b)); 47 } 48 else if ("multiply".equals(op)) { 49 System.out.println("result=" + (a * b)); 50 sendPage(uri + "displayResult", new VarMap().add("a", a).add("b", b).add("operator", op).add("result", a * b)); 51 } 52 else if ("divide".equals(op)) { 53 if (b == 0) { 54 } 56 else { 57 System.out.println("result=" + (a / b)); 58 sendPage(uri + "displayResult", new VarMap().add("a", a).add("b", b).add("operator", op).add("result", a / b)); 59 } 60 } 61 else { 62 } 64 } 65 } 66 | Popular Tags |