Skip to content

Commit 62fcbee

Browse files
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

File tree

1 file changed

+0
-5
lines changed

1 file changed

+0
-5
lines changed

Section10Methods/src/Item.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ public static void main(String[] args) {
88
c.Show();
99
}
1010
}
11-
12-
13-
1411
class Calculate {
1512
int p, q, total;
1613
void getData() {
@@ -20,11 +17,9 @@ void getData() {
2017
System.out.println("Enter the quantity of the product:");
2118
q = sc.nextInt();
2219
}
23-
2420
void Result() {
2521
total = p*q;
2622
}
27-
2823
void Show() {
2924
System.out.println("Total price is: "+total);
3025
}

0 commit comments

Comments
 (0)