package helloworld;

import java.util.function.Consumer;

import org.requirementsascode.UseCaseModel;
import org.requirementsascode.UseCaseRunner;

public class HelloWorld03_UserEntersNameAndAgeExample extends AbstractHelloWorldExample{
	private String firstName;
	private String age;
	
	public void start() {	
		UseCaseRunner useCaseRunner = new UseCaseRunner();
		UseCaseModel useCaseModel = useCaseRunner.getUseCaseModel();
				
		useCaseModel.newUseCase("Get greeted")
			.basicFlow()
				.newStep("User enters first name. System saves the first name.")
					.handle(EnterTextEvent.class).system(saveName())
				.newStep("User enters age. System saves age.")
					.handle(EnterTextEvent.class).system(saveAge())
				.newStep("System greets user with first name and age.")
					.system(greetUserWithFirstNameAndAge());
		
		useCaseRunner.run();
		
		String firstName = enterText("Please enter your first name: ");
		useCaseRunner.reactTo(new EnterTextEvent(firstName));
		
		String age = enterText("Please enter your age: ");
		useCaseRunner.reactTo(new EnterTextEvent(age));
		
		theEnd();
	}

	private Consumer<EnterTextEvent> saveName() {
		return enterTextEvent -> firstName = enterTextEvent.getText();
	}
	
	private Consumer<EnterTextEvent> saveAge() {
		return enterTextEvent -> age = enterTextEvent.getText();
	}
	
	private Runnable greetUserWithFirstNameAndAge() {
		return () -> System.out.println("Hello, " + 
			firstName + " (" + age + ").");
	}
	
	public static void main(String[] args){
		new HelloWorld03_UserEntersNameAndAgeExample().start();
	}
}

@@ -266,22 +266,19 @@
 private 
-Str
 in
-g
+t
  age;%0A%09%0A
@@ -1280,24 +1280,41 @@
 nt -%3E age = 
+Integer.parseInt(
 enterTextEve
@@ -1317,32 +1317,33 @@
 tEvent.getText()
+)
 ;%0A%09%7D%0A%09%0A%09private 

Update HelloWorld03 to parse text for age