100 likes | 234 Views
Step wise refinement. This time implement your solution by using high level methods you wish you had. Then implement those methods using simpler high level methods you wished you had. Continue in this manner until you are invoking the primitive methods to implement you higher level methods.
E N D
Step wise refinement • This time implement your solution by using high level methods you wish you had. • Then implement those methods using simpler high level methods you wished you had. • Continue in this manner until you are invoking the primitive methods to implement you higher level methods.
Sample Problem • Design a Robot to lay Beepers in a overpass walkway pattern. • Start Robot at 2,3, ends at 2,14 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10 11 12 13
Step One • Implement the task method using whatever magical methods I want. public void task() { climbUpStairs(); walkAcrossTop(); climbDownStairs(); } • Notice that each new word begins with a capital letter
Step Two • Implement those magical methods. • First implement climbUpStairs public void climbUpStairs() { moveTwo(); turnRight(); moveThree(); }
Step Three • Now implement those magical methods. • moveTwo(), turnRight() and moveThree(); public void moveTwo(){ move(); move(); } public void moveThree(){ moveTwo(); move(); } public void turnRight(){ you’ve seen already }
Step Four • Test climbUpStairs • In the task method, Comment out: walkAccrossTop and climbDownStairs as shown below: public void task() { climbUpStairs(); // walkAcrossTop(); // climbDownStairs(); } And execute MainDriver1. Does climbUpStairs work as desired? If not fix it!
Fix climbUpStairs public void climbUpOneStair() { turnLeft(); moveTwo(); turnRight(); moveTwo(); } public void climbUpStairs() { climbUpOneStair(); climbUpOneStair(); climbUpOneStair(); }
Step Five • Implement walkAcrossTop • Test walkAcrossTop by uncommenting the call to walkAcrossTop in the task method as shown below public void task() { climbUpStairs(); walkAcrossTop(); // climbDownStairs(); }
Step Six • Implement climbDownStairs • Test climbDownStairs by uncommenting the call to climbDownStairs in the task method as shown below public void task() { climbUpStairs(); walkAcrossTop(); climbDownStairs(); }
Your final Karel Task • Time for one last karel assignment before returning to Alice! • See worksheet