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:
- Takes two numbers and an operator (
+,-,*,/). - Performs the correct operation.
- Handles bad input gracefully instead of crashing.
- 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
Decimalnumbers and aStringoperator. - Processing — what happens to that data? Here: pick the right arithmetic operation and run it.
- Output — what comes out? Here: a formatted
Stringdescribing 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.
Plan the Program Quiz
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.