assignment 3: dodo goes complex - radboud...

18
Assignment 3: Dodo goes complex Algorithmic Thinking and Structured Programming (in Greenfoot) © Renske Smetsers-Weeda & Sjaak Smetsers Contents Introduction Learning objectives Instructions Theory . Using sub-methods ................................................ . Decomposing problems ............................................. . Code Alignment .................................................. . Logical Operators ................................................. . Loading a world .................................................. . Saving a world ................................................... . Using Strings .................................................... Challenges . Using sub-methods ................................................ . Lay an egg in each nest ............................................. . No double eggs ................................................... . Walk through a tunnel .............................................. . Walk to nest, climbing over any fences .................................... . Walk around a fenced area ........................................... . Find the nest by following a trail of eggs ................................... . Simple Maze .................................................... . Complex Maze ................................................... . Dodo goes wild .................................................. Reection Saving and Handing in Licensed under the Creative Commons Attribution . license: https://creativecommons.org/licenses/by/4.0/

Upload: dangbao

Post on 11-Mar-2018

231 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Assignment 3: Dodo goes complex

Algorithmic Thinking and Structured Programming (in Greenfoot)© 2017 Renske Smetsers-Weeda & Sjaak Smetsers1

ContentsIntroduction 1

Learning objectives 1

Instructions 1

Theory 23.1 Using sub-methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23.2 Decomposing problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33.3 Code Alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33.4 Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43.5 Loading a world . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43.6 Saving a world . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53.7 Using Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Challenges 73.1 Using sub-methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.2 Lay an egg in each nest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.3 No double eggs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.4 Walk through a tunnel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.5 Walk to nest, climbing over any fences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.6 Walk around a fenced area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.7 Find the nest by following a trail of eggs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.8 Simple Maze . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.9 Complex Maze . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.10 Dodo goes wild . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13Reflection 16

Saving and Handing in 17

1Licensed under the Creative Commons Attribution 4.0 license: https://creativecommons.org/licenses/by/4.0/

Page 2: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Dodo goes complex Assignment 3

IntroductionIn the previous assignments you have become acquainted with Greenfoot and algorithmic thinking.You are able to read, write and debug your own code. You also practiced devising generic solutions andimplementing them. In this assignment you will learn how to design code as separate components:making it easier to write, test and re-use your solution. Splitting problems into smaller parts makes iteasier to solve complex problems.This assignment’s goal is: decompose problems into manageable parts.

Learning objectivesAfter completing this assignment, you will be able to:

• decompose a (complex) problem into subproblems;• apply decomposition in flowcharts and code by identifying sub-methods;• design, write and test sub-methods separately;• describe the role of a method’s result type and parameter(s);• re-use existing sub-methods and solutions;• create conditional expressions by combining logical operators;• apply nesting as a strategy for solving problems;• design generic solutions;• assess and evaluate your solution.

InstructionsIn this assignment you will carry on with your code from the previous assignment. Make a copy of thatscenario to continue working with. To make a copy follow the next steps:

• Open your scenario from the previous assignment.• In the Greenfoot menu at the top of the screen, select ’Scenario’ and then ’Save As ...’.• Check that the window opens in the folder where you want to save your work.• Choose a file name containing your own name(s) and the current assignment number, for example:Asgmt3_John .

Note: We recommend that you to continue working with your own code. If it is absolutely impossibleto carry on working with your own code from the previous assignment, then you may download a newscenario from the course website2.Throughout the assignment you will also need to answer some questions. The following must behanded in:• All flowcharts: use pencil and paper, or go to https://www.draw.io/;

2http://course.cs.ru.nl/greenfoot/

Algorithmic thinking and structured programming (in Greenfoot) 1

Page 3: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Dodo goes complex Assignment 3

• Your code: the file MyDodo . jav contains all your code and must be handed in;• The reflection sheet: complete and hand it in.You must discuss all other answers with a programming partner. Jot down a short answer on (theassignment) paper.

There are three types of challenges:Recommended. Students who need more practice or with limited programming experienceshould complete all of these.Mandatory. Everyone must complete these.Excelling. More inquisitive tasks, designed for students who completed 2 star tasks and areready for a bigger challenge.Students who skip 1-star challenges should complete all 3-star challenges.

A note in advance:• In this assignment you may only make changes to the MyDodo class;• You may use methods from the MyDodo or Dodo class, not from the Actor class;• Teleportation is not permitted: if Mimi needs to get somewhere, she must walk there!

Theory

Theory 3.1: Using sub-methodsIf a particular set of instructions are repeated several times, it can be useful to place them in a sub-method. When the set of instructions is required, only the sub-method needs to be called. This saves alot of error-prone typing, and moreover, makes testing and re-use easier.ExampleTo take a step backwards, Mimi has to:

• turn 180 degrees (by calling: turnRight ( ) and turnRight ( ) ),• move, and then• turn 180 degrees again (again by calling: turnRight ( ) and turnRight ( ) ).

For Mimi to take several steps backwards, would lead to a repetition of lots of steps. In this case, itwould be better to write a sub-method called stepOneCellBackwards ( ) (see the code in figure 1). Now,to call this sub-method use: stepOneCellBackwards ( ); (see the code in figure 2).

Algorithmic thinking and structured programming (in Greenfoot) 2

Page 4: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Dodo goes complex Assignment 3

Figure 1: Code for stepOneCellBackwards ( )

Figure 2: Calling stepOneCellBackwards ( )

Theory 3.2: Decomposing problemsA complex problem (and its solution), can be made easier when you break this down into several smallerproblems. In code, these steps are written in a sub-method, which can be designed and tested sepa-rately (see Theory 3.1). The sub-methods are then combined together to create a complete solution tothe entire problem at hand. The process of breaking a large problem into smaller problems is calleddecomposition.

Figure 3: Decomposing a problem into parts and tackling each separatelyDecomposition is used in the following cases:• complex problem: when a problem or set of instructions is so complex that it would be better (lesserror-prone) to design, develop and test them separately.• repetition: if a particular series of steps repeat;• many steps: when an algorithm becomes unclear and hard to follow by numerous amount of de-tailed steps (for example: more than seven).• cohesive set of instructions: if a set of instructions form a fairly independent and complete set ormodule (which may in the future could be re-used elsewhere);

By means of decomposition the code becomes easier to understand, test, re-use modify, and extend.Theory 3.3: Code AlignmentLogical and consistent use of style makes code more readable. Style conventions exist, just like namingconventions. Indenting is not required for the program to work and has no effect on how the programis executed. However it is a good programming practice. Examples are indenting blocks of code andconsistently placing curly brackets. Greenfoot can help you align your code by using Ctrl-Shift-I. Figure5 shows code which is aligned:

Algorithmic thinking and structured programming (in Greenfoot) 3

Page 5: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Dodo goes complex Assignment 3

Figure 4: Example of not aligned code

Figure 5: Example of aligned codeSee http://google-styleguide.googlecode.com/svn/trunk/javaguide.html for a complete list of styleand naming conventions.Theory 3.4: Logical OperatorsJava has three logical operators, shown in the table below. You have already seen (and used) a few ofthem. You can combine these with boolean methods to create a conditional expression which describesa particular selection (i.e. choice).

Operator Meaning Example&& AND facingNorth ( ) && fenceAhead ( )|| OR fenceAhead ( ) || borderAhead ( )! NOT ! fenceAhead ( )

Combining logical operatorsYou can combine logical operators to create more complex conditional expressions. As a result it cansimplify your code. However, combining logical operators, especially with a negation (the NOT) can betricky. In addition, you should use parentheses to be clear on what belongs together.

Expression Equal to Meaning!( A && B ) ! A || ! B Is true as soon as either A or B is not true!( A || B ) ! A && ! B Is only true if neither A or B are true

Examples• NO (hitting OR kicking) ⇒ !( hitting || kicking ) ⇒ ! hitting && ! kicking .Which means (obviously), you may do neither of them.• NO (skirt AND pants) ⇒ !( skirt && pants ) ⇒ ! skirt || ! pants.Which means, you can have either of them, but not both of them (that would look silly).

Theory 3.5: Loading a worldTo load a particular world each time you compile, follow this example. In the next steps we will load theworld ’worldEmptyNestsTopRow’:

1. Right-click on ’Madagaskar’ in the class diagram.

Algorithmic thinking and structured programming (in Greenfoot) 4

Page 6: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Dodo goes complex Assignment 3

2. Select ’Open Editor’.3. Near the top you will find the following code fragment:

Figure 6: Opens an empty world (initial configuration)4. Replace the filename (the part in front of ’.txt’) with the world you wish to open (for example:’worldEmptyNestsTopRow’). It should then look like this:

Figure 7: Opens ’worldEmptyNestsTopRow’ file

Theory 3.6: Saving a worldTo save a scenario, follow the next steps:

1. Right-click on an empty cell in the world.2. Select ’saveToFile ( ) ’.3. The scenario has now been saved to a new file called ’saved.txt’, which can be found in the ’worlds’folder.

Theory 3.5 describes how to load a particular world each time you compile.Theory 3.7: Using StringsIn Java, text is called a String . String is a type, just like int and boolean . Methods can have a String(or text) as a parameter. You have already used this to print tekst to a console (see also Theory 1.14). Touse a particular text in your program, you need to use quotation marks. Here are some examples.

• define a String as follows: String text1 = "Hello" ;• use a String as a parameter:

Figure 8: Code Figure 9: Output in console

• glue two String together (called concatenate) using ’+’.

Algorithmic thinking and structured programming (in Greenfoot) 5

Page 7: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Dodo goes complex Assignment 3

Figure 10: CodeFigure 11: Output in console

• also concatenate a String and an int variable int nrOfEggsFound using ’+’.

Figure 12: Code

Figure 13: Output in console

The method showCompliment ( String compliment ) has a String parameter with the name ’compli-ment’. Figure 16 show the same result for calling either of the following code examples (figure 14 andfigure 15).

Figure 14: Code with output figure 16 Figure 15: Code with output figure 16

Figure 16: Output for code in either figure 14 or 15

Algorithmic thinking and structured programming (in Greenfoot) 6

Page 8: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Dodo goes complex Assignment 3

Challenges

Please read Theory 3.1: Using sub-methods.

Please read Theory 3.2: Decomposing problems.

Challenge 3.1: Using sub-methodsIn challenge 2.5 you wrote a method boolean grainAhead ( ) which tested whether there is a grain inthe cell in front of Mimi (see flowchart 17).

Figure 17: Flowchart for grainAhead

Your next challenge is to use sub-methods to clean up the code in the methodboolean grainAhead ( ) .

a) Write a method stepBack ( ) which makes Mimi take one step back, facing in the original direc-tion. Also add JavaDoc comments.b) Replace the circled code by a call of stepBack , according to the following flowchart:

Algorithmic thinking and structured programming (in Greenfoot) 7

Page 9: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Dodo goes complex Assignment 3

Figure 18: Flowchart for grainAhead using submethod stepBack

c) Test your program.d) Can you clean up any more code in the grainAhead method?e) Test your program after any (minor) modifications.

Please read Theory 3.3: Code Alignment.

Please read Theory 3.4: Logical Operators.

Please read Theory 3.5: Loading a world.

Please read Theory 3.6: Saving a world.

Challenge 3.2: Lay an egg in each nestYour mission is as follows:

”Mimi walks to the edge of the world. If she finds a nest, she lays an egg in it.”Make sure your algorithm is generic. It must work in any similar world, so also if one of the nests ismoved one position to the right or left, or an additional nest is added.

a) Open the ’worldEmptyNestsTopRow’ world.b) Fill in the empty slots in the flowchart in figure 19.

Figure 19: Flowchart for walking to the edge of the world and laying an egg in each nestc) Write the corresponding code (and comments) for your method. Also properly align your code (seeTheory 3.3).

Algorithmic thinking and structured programming (in Greenfoot) 8

Page 10: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Dodo goes complex Assignment 3

d) Test your method by right-clicking on Mimi in the world, and then selecting the method. Tip:Theory 3.5 describes how to load a particular world each time you restart the scenario.e) Does the program work as expected? There’s a problem with the flowchart. Can you find it?f) Propose a correction for the flowchart and change the code accordingly.g) Test again.

You have now written an if .. then .. else .. statement nested in a while loop.Challenge 3.3: No double eggsThe next mission is:

”Mimi walks to the edge of the world. If she finds a nest without an egg, then she must lay an egg.”Obviously, Mimi should only lay an egg if there is no egg there yet.

a) Open the ’worldEmptyNestsTopRow’ world and place an egg in a few nests. Tip: Theory 3.5 de-scribes how to load a particular world each time you want to run your code.b) Describe the initial and final situations.c) Sketch a suitable flowchart.d) Write and test the corresponding code (and comments) for your method. Also properly align yourcode (see Theory 3.3).

You have now used either nesting or logical operators to test for certain conditions.Challenge 3.4: Walk through a tunnelYour mission is to teach Mimi to walk through a tunnel of fences (see figure 20), and stop when she getsclear of the tunnel (see figure 21).

Figure 20: Initial situation Figure 21: Final situationFirst we break the problem down into sub-problems which can each be tackled separately:

Algorithmic thinking and structured programming (in Greenfoot) 9

Page 11: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Dodo goes complex Assignment 3

Figure 22: Decomposing the problem into sub-problems which can be tackled separatelya) Write and test a sub-method which checks whether Mimi has a fence to her left side.b) Write and test a similar sub-method which checks whether Mimi has a fence to her right side.c) Using these sub-methods, write and test method void walkThroughTunnel ( ) . You can use ’world-Tunnel’ file for testing the world (Theory 3.5 explains how to load the world).You have now applied abstraction to break a large problem down into smaller parts. Using the divide-and-conquer principle, you have designed, implemented, and tested sub-problems (fenceOnRight ( )and fenceOnLeft ( ) ). You used your solution to the sub-problems in walkThroughTunnel ( ) and testedyour program as a whole.Who knows, maybe you can use one of your methods (such as fenceOnRight ( ) ) in a followingchallenge. That would be convenient, after all, you’ve tested the methods and are convinced they workproperly. This is called modularization.

Challenge 3.5: Walk to nest, climbing over any fencesMimi is looking for her nest. On her way there, she must climb over any fences she comes across. If shefinds her nest, she should lay an egg in it and stop. If she reaches the end of the world before she findsher nest, she should stop and show a pop-up window with an appropriate error message.

Tips:• Sketch a high-level flowchart first.• It may be useful to have a look back at challenge 2.8 where you designed code for

walkToWorldEdgeClimbingOverFences ( ) .• Load world ’worldFencesAndNest’.• For an error pop-up, use: showError ( String message )

Algorithmic thinking and structured programming (in Greenfoot) 10

Page 12: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Dodo goes complex Assignment 3

Challenge 3.6: Walk around a fenced areaYour mission is to teach Mimi to walk around a fenced area.

a) Open the ’worldFencedArea’ world.b) Determine the initial and final situations. Come up with a suitable algorithm. Tip: To avoid Mimiwalking around the fenced area for ever, we will assume that there is an egg in the very last squareon her route: if she finds the egg she will know that she’s done.c) Write the corresponding method void walkAroundFencedArea ( ) which makes Mimi walk aroundthe fenced area. Also add comments.d) Compile and test your method. Also check if your program works with a larger fenced area.e) Test in which initial situations your program works. If necessary, adjust your description of theinitial situation.f) Also test if your method works in another world, such as: ’worldOtherFencedArea’. If necessary,modify your algorithm (and thus flowchart and code) so that it also works in this world.

Figure 23: Another fenced areaYou have now written a generic method with which Mimi can walk around any fenced area. Youapplied modularization by re-using (existing and tested) methods.

Challenge 3.7: Find the nest by following a trail of eggsYour mission is to help Mimi follow a trail of eggs until she reaches her nest (see world: ’worldEggTrail-ToNest’).

Figure 24: Task: follow the egg trail until nestBreak the problem down into more manageable sub-problems.

Algorithmic thinking and structured programming (in Greenfoot) 11

Page 13: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Dodo goes complex Assignment 3

a) Draw a high-level flowchart showing which sub-methods you need to design and write.b) For each sub-method:

• Choose an appropriate name (and return-type);• Determine the initial and final situations;• Write and test.

c) Using these sub-methods, write and test your solution as a whole.d) Test if your method works for another trail of eggs, for example in the ’worldEggTrailToNest2’world. You may discover that you still need to make some changes.e) Assess your approach. What went well? What could you do better next time?

Please read Theory 3.7: Using Strings.

Challenge 3.8: Simple MazeCan you help Mimi find her way to her nest through the maze to her nest? Give Mimi a complimentwhen she finds her nest. Of course, your solution has to be generic: Mimi has to be able to find her waythrough any arbitrary maze.

You may assume the following:• The world is surrounded by a fence.• There is exactly one nest.• The nest is located next to a fence.• A route to the nest exists.• At most one route exists (there are no dead-ends, and no ’islands’ of fences).• From the initial position, Mimi can only walk in one direction.

Write a method helping Mimi find her nest:a) Come up with a suitable algorithm and draw a high-level flowchart.b) Design, implement, and test sub-methods for your algorithm.c) Write the code for your solution and test it. Also test using the following mazes:

Algorithmic thinking and structured programming (in Greenfoot) 12

Page 14: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Dodo goes complex Assignment 3

• ’worldMazeLevel1a’.• ’worldMazeLevel1b’.• ’worldMazeLevel1c’.

d) Assess your program. Which improvements can you suggest? You don’t necessarily need to im-plement them, just list them.

Challenge 3.9: Complex MazeCan you help Mimi find her way to her nest through a complicated maze? Give Mimi a compliment(using a pop-up) when she finds her nest. Of course, your solution has to be generic: Mimi has to be ableto find her way through any arbitrary maze.

You may now assume the following:• The world is surrounded by a fence.• There is exactly one nest.• The nest is located next to a fence.• A route to the nest exists.• There are no ’islands’ of fences.

Write a method helping Mimi find her nest:a) Come up with a suitable algorithm and draw a high-level flowchart.b) Design, implement, and test sub-methods for your algorithm.c) Write the code for your solution and test it. Also test using the following mazes:

• ’worldMazeLevel2a’.• ’worldMazeLevel2b’.• ’worldMazeLevel2c’.

d) Make your own maze. Test a classmates program with it.e) Exchange your solution with a classmate and give each other feedback.Hint: In one of the previous exercises you used a ’trick’ to determine if Mimi had been in that spotbefore.

Algorithmic thinking and structured programming (in Greenfoot) 13

Page 15: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Dodo goes complex Assignment 3

Challenge 3.10: Dodo goes wildNow on to a more challenging algorithmic thinking puzzle. Suppose we have a method jumpToEnd ( ) .This makes Mimi repeatedly take steps until she cannot move any further (either a fence is blockingher path or she has reached the end of the world):public void jumpToEnd ( ) {

while ( ! borderAhead ( ) && ! fenceAhead ( ) ){step ( ) ;

}}

The jumpToEnd ( ) method is called in the method goWild ( ) .

Figure 25: Flowchart for method goWild ( )The scenario is executed by running goWild . Three different initial configurations are shown below:

Figure 26: A Figure 27: B Figure 28: Ca) Does Mimi stop for configuration A? If so, how often was the jumpToEnd ( ) method called?b) Does Mimi stop for configuration B? If so, how often was the jumpToEnd ( ) method called?c) Verify your answers by adding print statements to the code. (See Theory 1.14 and Theory 3.7 onhow to print to the console).

Algorithmic thinking and structured programming (in Greenfoot) 14

Page 16: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Dodo goes complex Assignment 3

d) What happens with the program if Mimi doesn’t stop?e) Suppose we want to Mimi to find the egg in configuration C. We can do this by placing fences in theworld, at carefully selected locations. You may not place a fence immediately next to the border.Place the fences in figure C such that you need no more than 5 fences for Dodo to find the egg afterthe goWild ( ) method is called.

Algorithmic thinking and structured programming (in Greenfoot) 15

Page 17: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Dodo goes complex Assignment 3

ReflectionIn this assignment you practiced designing code as separate components, making it easier to write, testand re-use your solution. One of the most important steps in becoming good at anything is to evaluateand reflect on what you did and how it went:ResultI know my solution works because . . .I am proud of my solution because . . .I could improve my solution by . . .

MethodMy approach was good because . . .What I could do better next time is . . .

Fill the following table with smileysindicating how things went. I can do itI did it a bit but didn’t fully get itI didn’t get it at all

I can describe an algorithm by drawing a high-level flowchart

I can identify sub-methods in an algorithm

I can design, write and test sub-methods separately

I can combine logical operators to create conditional expressions

I can design generic solutions

Algorithmic thinking and structured programming (in Greenfoot) 16

Page 18: Assignment 3: Dodo goes complex - Radboud Universiteitcourse.cs.ru.nl/greenfoot/docs/Opdrachten3.0/DodoAssignment3...Assignment 3: Dodo goes complex ... 3.5 Loading a world ... •

Dodo goes complex Assignment 3

Saving and Handing inYou have just finished the assignment. Save your work! You will need this for future assignments. In theGreenfoot menu at the top of the screen, select ’Scenario’ and then ’Save’. You now have all the scenariocomponents in one folder. The folder has the name you chose when you selected ’Save As ...’.Handing inHand in the following:

• Your code: The java file MyDodo . jav;• Flowcharts: paste (photo’s of) your flowcharts in a Word document;• The reflection sheet: complete and hand it in.

Algorithmic thinking and structured programming (in Greenfoot) 17