Commit 62fcbee
committed
feat: Implement Item and Calculate classes for total price computation
WHAT the code does:
Defines an Item class containing the main() entry point.
Implements a Calculate class that:
- Uses Scanner to take product price and quantity from user input
- Multiplies price and quantity to compute total cost
- Prints the total cost to the console
WHY this matters:
Provides a simple example of separating concerns:
Item handles program entry, while Calculate encapsulates logic.
Introduces Scanner usage for runtime input and demonstrates method-based design.
Useful for beginners learning basic Java classes and method invocation.
HOW it works:
Execution begins in Item.main().
A Calculate object is instantiated and its methods are called in sequence:
getData() prompts the user and stores inputs
Result() computes the multiplication of inputs
Show() prints the result
Tips and gotchas:
Scanner should be closed after input to prevent resource leaks.
No validation is present, so invalid or negative inputs are still accepted.
Calculation logic is tightly coupled with console I/O, making testing less flexible.
Use-cases:
Educational exercises to teach Java class structure and method usage.
Basic billing or checkout total calculators.
Foundation for extending into more complex systems with discounts, taxes, or multiple items.
Short key: class-item calculate-price-total.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 29b8119 commit 62fcbee
1 file changed
+0
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | 11 | | |
15 | 12 | | |
16 | 13 | | |
| |||
20 | 17 | | |
21 | 18 | | |
22 | 19 | | |
23 | | - | |
24 | 20 | | |
25 | 21 | | |
26 | 22 | | |
27 | | - | |
28 | 23 | | |
29 | 24 | | |
30 | 25 | | |
| |||
0 commit comments