<taskModel about="Maylene Waltz" xmlns="http://ce.org/cea-2018">
	<task id="coffee">
		<subtasks id="coffeeSteps" ordered="true">
			<step name="wand" task="wand" minOccurs="0" maxOccurs="1"></step>
			<step name="select" task="select" minOccurs="1" maxOccurs="1"></step>
			<step name="pay" task="pay" minOccurs="1" maxOccurs="1"></step>
			<binding slot="$select.input" value="$wand.output"/>
			<binding slot="$select.coffee" value="$wand.coffee"/>
			<binding slot="$pay.input" value="$wand.output"/>
			<binding slot="$pay.price" value="$select.output"/>
		</subtasks>
	</task>
	
	<task id="wand">
		<output name="output" type="boolean"/>
		<output name="coffee" type="Coffee"/>
		<subtasks id="wandSteps" ordered="true">
			<step name="haveWand" task="haveWand" maxOccurs="1"></step>
			<step name="defaultCoffee" task="defaultCoffee" maxOccurs="1"></step>	
			<binding slot="$defaultCoffee.input" value="$haveWand.output"/>
			<binding slot="$this.output" value="$haveWand.output"/>
			<binding slot="$this.coffee" value="$defaultCoffee.coffee"/>
		</subtasks>
	</task>
	
	<task id="haveWand">
		<output name="output" type="boolean"/>
	</task>
	
	<task id="defaultCoffee">
		<input name="input" type="boolean"/>
		<output name="coffee" type="Coffee"/>
		<subtasks id="enterNumberSteps">
			<step name="enterValidNumber" task="enterValidNumber"></step>
			<step name="getWandCoffee" task="getWandCoffee"></step>
			<applicable>$this.input == true</applicable>
			<binding slot="$this.coffee" value="$getWandCoffee.output"/>
		</subtasks>
		
		<subtasks id="setDefaultCoffeeSteps">
			<step name="setDefaultCoffee" task="setDefaultCoffee"></step>
			<applicable>$this.input == false</applicable>
			<binding slot="$this.coffee" value="$setDefaultCoffee.output"/>
		</subtasks>
	</task>
	
	<task id="enterValidNumber">
		<postcondition sufficient="true">isValidWandNumber()</postcondition>
		<subtasks id="enterValidNumberSteps">
			<step name="enterNumber" task="enterNumber"></step>
			<step name="again" task="enterValidNumber"></step>
		</subtasks>
	</task>
	
	<task id="enterNumber">
	</task>
	
	<task id="getWandCoffee">
		<output name="output" type="Coffee"/>
		<postcondition>$this.output != undefined</postcondition>
		<script>
			importClass(Packages.coffee.NumberPadPanel);
			
			// Get the saved coffee for this wand number
			var wandNumber = NumberPadPanel.getWandNumberInt();
			if (wandNumber &gt; -1) {
				var cof = lookup(wandNumber);
				if (cof != undefined) {
					$this.output = cof;
				}
			}
		</script>
	</task>
	
	<task id="setDefaultCoffee">
		<output name="output" type="Coffee"/>
		<postcondition>$this.output != undefined</postcondition>
		<script>
			$this.output = new Coffee(1,true,true);
		</script>
	</task>
	
	<task id="select">
		<input name="input" type="boolean"/>
		<input name="coffee" type="Coffee"/>
		<output name="output" type="string"/>
		
		<subtasks id="selectWithWandSteps" ordered="true">
			<step name="selectWithWand" task="selectWithWand" minOccurs="1" maxOccurs="1"></step>
			<applicable>$this.input == true</applicable>
			<binding slot="$selectWithWand.coffee" value="$this.coffee"/>
			<binding slot="$this.output" value="$selectWithWand.output"/>
		</subtasks>
		
		<subtasks id="selectWithoutWandSteps" ordered="true">
			<step name="selectWithoutWand" task="selectWithoutWand" minOccurs="1" maxOccurs="1"></step>
			<applicable>$this.input == false</applicable>
			<binding slot="$this.output" value="$selectWithoutWand.output"/>
		</subtasks>
	</task>
	
	<task id="selectWithWand">
		<input name="coffee" type="Coffee"/>
		<output name="output" type="string"/><!--  price  -->
		<script>
			importClass(Packages.coffee.CenterPanel);
			// get Coffee attributes from GUI and save/set/store here
			$this.output = calculateCost(CenterPanel.getCoffeeSize(),CenterPanel.isHot());
		</script>
	</task>
	
	<task id="selectWithoutWand">
		<output name="output" type="string"/><!--  price  -->
		<script>
			importClass(Packages.coffee.CenterPanel);
			// get Coffee attributes from GUI and save/set/store here
			$this.output = calculateCost(CenterPanel.getCoffeeSize(),CenterPanel.isHot());
		</script>
	</task>
	
	<task id="pay">
		<input name="input" type="boolean"/>
		<input name="price" type="string"/>	
	</task>
	
	<script init="true">
		
		// define Coffee class
		function Coffee(size, caff, temp) {
			this.size = size;
			this.caff = caff;
			this.temp = temp;
		}
		
		var smallRegHot = new Coffee(0,true,true),
			medDecafHot = new Coffee(1,false,true),
			largeRegIced = new Coffee(2,true,false);
			
		var wands = [
			{ wandNumber: 852, coffee: smallRegHot},
			{ wandNumber: 137, coffee: medDecafHot},
			{ wandNumber: 538, coffee: largeRegIced} ];
		
		// Lookup the coffee for the given wandNumber
		function lookup(wandNum) {
			for (i = 0; i &lt; 3; i++) {
				if (wands[i].wandNumber == wandNum)
					return wands[i].coffee;
			}
		}
		
		// Calculate the cost of the coffee
		function calculateCost(size,hot) {
			var cost = 0.0;
			
			if (size == 0)
				cost += 1.70;
			else if (size == 1)
				cost += 1.80;
			else
				cost += 1.90;
			
			if (hot) 
				cost += 0.13;
			else
				cost += 0.29;
			
			return cost.toFixed(2);
		}
		
		function isValidWandNumber() {
			importClass(Packages.coffee.NumberPadPanel);
			
			// Return whether or not this is a valid wand number
			var wandNumber = NumberPadPanel.getWandNumberInt();
			if (wandNumber &gt; -1) {
				var cof = lookup(wandNumber);
				if (cof != undefined) {
					return true;
				}
			}
			return false;
		}
	</script>
</taskModel>