to acquire numerical user input private int readNumber(String message) { int tries = 0; while (true) { try { return Integer.valueOf(readString(message)); } catch (NumberFormatException e) { if (tries++ == 0) message += "<br/>Please enter a valid number!"; } } } //helper method used to acquire user input private String readString(String message) { Template template = Template.getInstance("Question"); template.set("message", message); String response = ret(template.renderHTML()); return template.parseResponse(response, "answer"); } public String run(String value) { String name = readString("Please enter your name: "); String country = readString("Please enter your country:"); int age = readNumber("Please enter your age:"); if (age < 70) { String email = readString("Please enter your email address:"); return "Name: "+name+", Country: "+country+", Age: "+age+", Email: "+email; } else { String telephone = readString("Please enter your telephone number:"); return "Name: "+name+", Country: "+country+", Age: "+age+", Tel: "+telephone; } } }