-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct.java
56 lines (48 loc) · 1.32 KB
/
product.java
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
48
49
50
51
52
53
54
55
56
class Product {
String name;
int code;
double amount;
public Product(String n, int c, double p) {
name = n;
code = c;
amount = p;
}
public void show() {
System.out.println("Product Name: " + name);
System.out.println("Product Code: " + code);
System.out.println("Sale Amount: " + amount);
}
}
class Sales extends Product {
int day;
double tax;
double totamt;
public Sales(String n, int c, double p, int day) {
super(n, c, p);
this.day = day;
this.tax = 0.0;
this.totamt = 0.0;
}
public void compute() {
if (day > 30) {
double fine = 0.025 * amount;
totamt = amount + tax + fine;
} else {
totamt = amount + tax;
}
}
public void show() {
super.show();
System.out.println("Number of Days Taken: " + day);
System.out.println("Service Tax: " + tax);
System.out.println("Total Amount Paid: " + totamt);
}
}
public class Main {
public static void main(String[] args) {
Sales sales = new Sales("Product A", 123, 1000.0, 45);
sales.tax = 0.124 * sales.amount; // Calculate service tax
sales.compute();
sales.show();
}
}