13. C# (Project A : The Method Calculator)
Source: Dev.to
Overview
A small project designed to enforce proper method design in C#.
The focus is on structure, not on complex mathematics.
Requirements
- No logic inside
Main– all responsibilities must be separated. - Input – ask the user for two numbers using
Console.ReadLine()and convert them withint.Parse(). - Operation selection – prompt the user to choose an operation (e.g., Add, Subtract, Get Remainder).
- Method dispatch – use an
if(orswitch) statement to call the appropriate method based on the user’s choice.
Expected flow
| User selection | Method to call |
|---|---|
| 1 | Add(num1, num2) |
| 2 | Subtract(num1, num2) |
| 3 | GetRemainder(num1, num2) |
Method Specifications
Each calculation method must:
- Accept two integers as parameters.
- Return an integer result.
- Never print anything; all output is handled in
Main.
int Add(int a, int b) { /* ... */ }
int Subtract(int a, int b) { /* ... */ }
int GetRemainder(int a, int b) { /* ... */ }
Guidelines
- Use
int.Parsefor converting string input to integers. - Employ the modulo operator (
%) for the remainder calculation. - Keep processing and output separate:
Mainshould only handle user interaction and display results. - Do not duplicate calculation logic inside
Main. - Do not hard‑code numbers or collapse everything into a single method.
Learning Objectives
- Think in terms of responsibilities and separation of concerns.
- Practice using parameters and return values correctly.
- Experience the benefits of refactoring and understanding why separation matters.
- Build a foundation for basic program architecture and method design.
If you encounter difficulties, that struggle is the intended part of the exercise—use it to deepen your understanding of clean code structure.