1 / 10

Step wise refinement

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.

aolds
Download Presentation

Step wise refinement

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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.

  2. 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

  3. 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

  4. Step Two • Implement those magical methods. • First implement climbUpStairs public void climbUpStairs() { moveTwo(); turnRight(); moveThree(); }

  5. 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 }

  6. 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!

  7. Fix climbUpStairs public void climbUpOneStair() { turnLeft(); moveTwo(); turnRight(); moveTwo(); } public void climbUpStairs() { climbUpOneStair(); climbUpOneStair(); climbUpOneStair(); }

  8. 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(); }

  9. 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(); }

  10. Your final Karel Task • Time for one last karel assignment before returning to Alice! • See worksheet

More Related