-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram64.java
More file actions
47 lines (36 loc) · 1.08 KB
/
Copy pathprogram64.java
File metadata and controls
47 lines (36 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Mini Shopping Cart
class Product {
String name;
double price;
int quantity;
Product(String name, double price, int quantity) {
this.name = name;
this.price = price;
this.quantity = quantity;
}
double getTotal() {
return price * quantity;
}
}
public class program64 {
public static void main(String[] args) {
Product[] cart = {
new Product("Keyboard", 1200, 1),
new Product("Mouse", 700, 2),
new Product("Headphones", 1500, 1)
};
double grandTotal = 0;
System.out.println("----- SHOPPING CART -----");
for (Product p : cart) {
double total = p.getTotal();
System.out.println(
p.name + " | ₹" + p.price +
" | Qty: " + p.quantity +
" | Total: ₹" + total
);
grandTotal += total;
}
System.out.println("-------------------------");
System.out.println("Grand Total: ₹" + grandTotal);
}
}