Skip to content
Tutorials Center
My learning

Topics

Lesson 48 of 50 ยท Practice and Interview

Practice Exercises with Solutions

Six hands-on software engineering exercises on SDLC costs, requirements, UML checks, design coupling, boundary testing and estimation, each with a runnable solution.

Reading about software engineering is only half the job; the other half is doing small pieces of it until the ideas stick. This lesson gives you six exercises, one for each major area of the tutorial: process, requirements, modeling, design, testing and estimation. Each exercise states a task, asks you to think first, and then shows a runnable solution you can edit.

The solutions are JavaScript stand-ins. Real software engineering is mostly conversation, judgment and diagrams, so a script cannot replace it, but it can make a rule precise enough to check. All numbers (defect counts, scores, prices) are invented for practice. A good routine: read the task, write your own answer on paper or in the editor, then run the solution and compare. Where yours differs, work out which one is better and why.

Six exercises

Process What do late defects cost?
Requirements Find the untestable ones.
Modeling Check a sequence diagram.
Design Detect a dependency cycle.

Two more cover testing and estimation.

1 / 2

Exercise 1: What do late defects cost?

Task. Defects are cheaper to fix the earlier you find them. Using the invented cost multipliers requirements 1, design 5, coding 10, testing 20 and production 100 (a base fix of 2 hours), compute the total fix cost for two projects: one without reviews and one with requirement and design reviews. Both projects introduce the same number of defects; only when they are found differs. This links to the Waterfall lesson, which discusses the cost of late change.

JS Cost of defects by phase

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Both projects introduced 40 defects, yet the reviewed project spends 1,140 hours instead of 2,034, saving 894. Most of the gain comes from the three production defects it avoids and the testing defects it catches earlier. The multipliers are illustrative; real ratios vary widely, but the direction is well supported. Follow-up: change the production multiplier to 30 and see how much of the saving remains.

Exercise 2: Find the untestable requirements

Task. Write a checker that flags requirement sentences with vague words, no "shall" or "must", two requirements joined by "and", or a limit without a number. See Functional and Non-Functional Requirements for what makes a requirement testable.

JS Requirement checker

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Four of six sentences are flagged. The checker is crude on purpose: it finds candidates for rework, and a human decides. It misses cases such as "The system shall be reliable" (no vague word on our list) and wrongly flags a legitimate sentence that happens to use "and" for one idea. Follow-up: add the word "reliable" and a rule that every requirement must mention a number or a named condition.

Exercise 3: Check a sequence diagram

Task. A sequence diagram is a list of messages between participants. Write a function that finds messages mentioning a participant that was never declared, then generate Mermaid text from the corrected model. Review Sequence and Activity Diagrams if the notation is unfamiliar.

JS Sequence diagram checker

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The first run finds that message 5 sends to a participant, Warehouse, that nobody declared. After adding it the model is consistent and the Mermaid text can be pasted into any Mermaid renderer. Treating a diagram as data is how diagram tools catch inconsistencies, such as a message that no class could receive. Follow-up: report any participant that is declared but never used.

Exercise 4: Detect a dependency cycle

Task. Modules should depend on each other in one direction. Given a dependency map, compute fan-out (modules each module uses) and fan-in (modules that use it), and find a cycle with a depth-first search. Cycles make modules impossible to understand or test alone; see Design Principles for cohesion and coupling.

JS Fan-in, fan-out and cycles

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The table shows users with fan-in 3 (everyone depends on it, so changing it is risky) and orders with fan-out 3. The search finds orders -> billing -> orders. Removing the billing -> orders dependency breaks the cycle. In real code the fix is usually to pass the data billing needs as a parameter, or to extract a shared module. Follow-up: report modules with fan-out of 3 or more as candidates for splitting.

Exercise 5: Boundary tests for a price rule

Task. A cinema charges nothing for ages 0 to 4, 8 for ages 5 to 17, 14 for ages 18 to 64 and 9 for ages 65 to 120; any other age is invalid. Generate boundary cases for every range, run the function on them and check ten expected values. See Test Design Techniques.

JS Boundary cases for ticket prices

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Each range contributes six values: just below the minimum, the minimum, just above, just below the maximum, the maximum and just above. Overlaps between neighboring ranges leave 18 distinct cases, including -1 and 121 for invalid ages. An off-by-one mistake such as age < 18 instead of age <= 17 would only show up at these edges. Follow-up: break ticketPrice on purpose and see which expected check fails first.

Exercise 6: Estimate the project

Task. Estimate a three-task project with three-point (PERT) estimates: the mean is (optimistic + 4 x likely + pessimistic) / 6 and the standard deviation is (pessimistic - optimistic) / 6. Then compare with basic COCOMO for 20,000 lines of code: effort = 2.4 x KLOC^1.05 person-months and schedule = 2.5 x effort^0.38 months. See Cost Estimation Models and Estimation and Planning.

JS PERT and COCOMO estimates

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The three tasks total 24.0 days with a standard deviation of about 3, so a range of roughly 18 to 30 days covers most outcomes. The total is the sum of the means, but the deviations combine as the square root of the summed variances. COCOMO suggests about 56 person-months over 11.5 months for 20 KLOC, a team near five. The two estimates answer different questions at different scales, so never present a single number as certain. Follow-up: double the pessimistic value of Checkout and see how the range widens.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Why does finding defects in requirements save so much effort?

    A defect found early is fixed before design, code and tests depend on it, so the rework is small.
  2. 2. What does a boundary value test of the range 5 to 17 include?

    Boundary analysis tests just outside, on and just inside each edge, where off-by-one mistakes hide.
  3. 3. A dependency cycle between two modules is a problem because

    Cycles are strong coupling: changes ripple both ways, and you cannot reuse or test either module alone.
  4. 4. In a PERT estimate, how do the standard deviations of several tasks combine?

    Variances add for independent tasks, so the total deviation is the square root of the summed squares.
  5. 5. Why is a script for finding vague requirements only a first filter?

    Word lists miss some problems and flag some good sentences, so humans must decide what to rewrite.

Summary

  • Six exercises practiced process cost, requirement quality, diagram consistency, dependency structure, boundary testing and estimation.
  • Treating diagrams, requirements and plans as data lets a program check rules that reviewers might miss, but it only finds candidates for human judgment.
  • Fix defects early, test the edges of every range, keep dependencies pointing one way, and give estimates as ranges.
  • Change the data in each exercise and predict the output before you run it; that is where the learning happens.

Next: Software Engineering Interview Questions.