Beginner 20 min read

Plan the Program

By the end of this lesson, you'll be able to:

  • Break a program down into inputs, processing, and output before writing any code
  • List the edge cases a calculator needs to handle
  • Explain why planning first saves rework later

Prerequisites: Module 7: "Repeating Work: Loops"

What we're building

Over this module you'll build a small Calculator class that:

  1. Takes two numbers and an operator (+, -, *, /).
  2. Performs the correct operation.
  3. Handles bad input gracefully instead of crashing.
  4. Presents the result in a clean, readable format.

Each lesson builds one piece. By the end, all four fit together into one working program.

Inputs, processing, output

Almost every program, no matter how complex, breaks down into the same three stages:

  • Input — what data comes in? Here: two Decimal numbers and a String operator.
  • Processing — what happens to that data? Here: pick the right arithmetic operation and run it.
  • Output — what comes out? Here: a formatted String describing the result.

Naming these explicitly before coding stops you from discovering halfway through that you forgot to handle a case.

A real-world analogy: a recipe before cooking

A chef reads the whole recipe before turning on the stove — checking they have every ingredient and understand every step — rather than discovering they're missing an ingredient halfway through. Planning a program the same way, on paper or in comments, catches missing "ingredients" (edge cases) before they become bugs.

Listing the edge cases up front

A calculator that only works for "nice" input like 10 + 5 isn't finished. Before building, list what could go wrong:

  • Division by zero (10 / 0)
  • An operator that isn't +, -, *, or / (like % or a typo)
  • Very large or very small decimal results that need clean formatting

Lesson 3 handles the first two; Lesson 4 handles the third. Naming them now means nothing gets forgotten later.

Exercise

As comments, list the three stages (input, processing, output) for a program that converts a temperature in Celsius to Fahrenheit.

Show hint

Input: a Decimal celsius value. Processing: apply the conversion formula. Output: a formatted String.

APEX

Plan the Program Quiz

1. Why plan a program's inputs, processing, and output before writing code?

Log in to submit the quiz and save your score.

My Notes

Log in to keep private notes on this lesson.

Questions about this lesson

No questions yet — be the first to ask.

Log in to ask a question about this lesson.

Summary

Before writing a single line of the calculator, this lesson maps out exactly what it needs to do — the same discipline professional developers apply before touching a keyboard.