Commit 6e0ad9b
committed
feat: Perform addition using encapsulated methods in Add class [oop-addition-basic]
🔑 Key: oop-addition-basic
🧠 Logic:
- Designed a class `Add` that encapsulates input, processing, and output:
• `getData()` → reads two integers `a` and `b` from user input.
• `getTotal()` → calculates sum of `a + b` and stores it in `total`.
• `showData()` → prints the result to console.
- Class `ClAdd` serves as the **driver** which creates an object of `Add` and sequentially calls its methods.
📌 Concepts Demonstrated:
- ✅ **Object-Oriented Programming** principles:
• **Encapsulation**: data and logic grouped in methods inside a class.
• **Modularity**: each method performs a distinct task (input, process, output).
- ✅ **Scanner class usage** for runtime input.
🧪 Flow of Execution:
1. `Add a = new Add();` → Object creation.
2. `getData()` → Prompts user and accepts input.
3. `getTotal()` → Computes `a + b`.
4. `showData()` → Displays the result.
📎 Use Cases:
- This is a basic template for understanding class-based design and separating logic for clarity and reusability.
Signed-off-by: Somesh diwan <[email protected]>1 parent 2c3343d commit 6e0ad9b
1 file changed
+6
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
| 3 | + | |
| 4 | + | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
10 | 8 | | |
11 | 9 | | |
12 | 10 | | |
13 | 11 | | |
14 | | - | |
15 | | - | |
| 12 | + | |
16 | 13 | | |
17 | 14 | | |
18 | | - | |
19 | | - | |
| 15 | + | |
20 | 16 | | |
21 | 17 | | |
22 | 18 | | |
23 | 19 | | |
24 | 20 | | |
25 | 21 | | |
26 | | - | |
27 | | - | |
| 22 | + | |
28 | 23 | | |
29 | 24 | | |
30 | 25 | | |
31 | | - | |
32 | | - | |
| 26 | + | |
33 | 27 | | |
34 | 28 | | |
35 | 29 | | |
0 commit comments