Project design
- Dart course
- Beginner
- Lesson 19/116
- 6 min
Design the structure of the calculator project and write the skeleton code.
Project: Calculator
In this project we will build a calculator step by step. We will add addition, subtraction, multiplication and division functions, handle errors and finally combine them with a menu.
Each lesson builds on the previous one; the initial code embeds the previous solution. You only add the new part. This method is common in real projects.
The first step is to write the program skeleton: void main() and a print that says 'Calculator ready'. In the next lessons we will add functions.
File structure
We will write the calculator in a single .dart file. void main() is the entry point; we add functions below it.
Suggested order: first main, then helper functions (add, subtract, ...). This makes the code easier to read.
Each function does one thing: add only adds, subtract only subtracts. This principle is called 'single responsibility'.
Practice Write the skeleton
Write void main() and add print('Calculator ready') inside. When the program runs we should see this message.
Starter code
// Write the calculator skeletonSample solution
void main() {
print('Calculator ready');
}Expected output
Calculator ready
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What will we write first in this project?
- User input
- Basic skeleton Correct answer
- Error handling
- Menu loop
Explanation: First the skeleton: void main and a print.
2 Entry point
void ____() { print('Calculator ready'); }
void main() { print('Calculator ready'); }
Explanation: main is the program's entry point.
3 Project concepts
| Term | Meaning |
|---|---|
main |
Entry point |
add |
Addition |
subtract |
Subtraction |
print |
Output |