AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Following a project plan

Week 29 · Unit 12: Be a problem solver · 3 lessons
2

Plan a small program

Computing 6: Unit 12, pp. 162–177
GoalFollow the stages to plan, build and test a small Scratch program with a loop and an if–else block.
New words
requirement · something that the program must doalgorithm · a set of steps to solve a problemtest plan · a table of tests with inputs, expected results and actual resultsboundary value · a test value on the edge of a rule, such as exactly 50 when the rule is 50 or more
Explanation

Here is a whole project for a savings jar program. We follow the stages in order. First, the requirements: the program asks three times how many coins were saved, it keeps a running total, it starts from 0 each time it runs, and at the end it says whether the goal of 50 was reached. Second, design: the flowchart uses a counter and a loop, and an if–else block at the end. Third, implementation: the blocks follow the flowchart. Fourth, testing: the test plan has normal values and boundary values around 50. Last, evaluation: we tick every requirement. Because a boundary can hide a bug, the test of exactly 50 is the most important.

NumberRequirement
R1asks three times: How many coins today?
R2keeps a running total
R3the total starts at 0 on every run
R4at the end it says Goal reached! for 50 or more, or Keep saving
Worked examples
Startset total to 0 and rounds to 0rounds < 3?yesask: How many coins today?add the answer to totaladd 1 to roundsnototal ≥ 50?yesnosay Goal reached!say Keep savingEnd
This is the design stage. The flowchart counts the rounds with a variable called rounds.
whenclickedsettotalto0askHow many coins today?and waitchangetotalbyanswerrepeat3sayGoal reached!for2secondssayKeep savingfor2secondsiftotal>49thenelse
This is the implementation. Scratch has no ‘50 or more’ block, so the test total ≥ 50 from the flowchart becomes total > 49. The loop repeats three times, so we do not need a rounds variable in Scratch. With the answers 20, 15 and 20 the total is 55, so the program says Goal reached!
InputsTotalExpectedActualResult
10, 10, 1030Keep savingKeep savingpass
25, 25, 050Goal reached!Goal reached!pass
25, 24, 049Keep savingKeep savingpass
0, 0, 00Keep savingKeep savingpass
This is the testing stage. The test plan includes the boundary at 50. The values just below and on the edge are the most useful tests.
Class activity

Paper project (no computer): choose a program with an if–else block, for example a program that says ‘Take an umbrella’ if the chance of rain is 50 or more, and ‘No umbrella’ if not. On one sheet write the five headings of the project plan. Write three requirements, draw the flowchart and write the blocks on paper strips. Your partner is the computer: give them three test inputs, including the boundary, and let them run your strips by hand. Fill in a test table. Did every test pass? If you have a computer or tablet, build the program in Scratch.

Practice
1
Trace the program for the answers 12, 8, 15 and 4. What does it say?
whenclickedsettotalto0askHow many stickers?and waitchangetotalbyanswerrepeat4sayAlbum full!for2secondssayKeep collectingfor2secondsiftotal>39thenelse
2
For the sticker program, write three tests with totals around the boundary of 40. Give the expected result of each.
3
Write two requirements for a program that tells a user whether they have enough money for a snack that costs 5 coins.
4
Look at the test results. The test with a total of exactly 50 says Keep saving, but the expected result is Goal reached!. What is the likely bug?
TestTotalExpectedActual
149Keep savingKeep saving
250Goal reached!Keep saving
351Goal reached!Goal reached!