-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoop5.java
More file actions
92 lines (45 loc) · 1.53 KB
/
Copy pathoop5.java
File metadata and controls
92 lines (45 loc) · 1.53 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import java.util.Scanner;
class AllProducts{
public String ProductName;
public int ProductId;
public void Product(){
Scanner s1 =new Scanner(System.in);
System.out.println("enter product name");
ProductName = s1.nextLine();
System.out.println("enter product Id");
ProductId = s1.nextInt();
System.out.printf("\n Product Name : %s \n Product Id : %d \n",ProductName,ProductId);
}
}
class UtilityProducts extends AllProducts{
public int discount;
public void Utility(){
System.out.println("\n welcome to utility products section");
Scanner s2 =new Scanner(System.in);
super.Product();
System.out.println("Please Enter price of product");
int price = s2.nextInt();
System.out.println("Please Enter discount");
discount = s2.nextInt();
discount = price - discount;
System.out.printf("\n Product Name : %s \n Product Id : %d \n Discounted Price j : %d \n",ProductName,ProductId,discount);
}
}
class foodProducts extends AllProducts{
public String DateOfExpiry;
public void food(String DateOfExpiry){
System.out.println("\nwelcome to Food produts section");
super.Product();
System.out.printf("\n Product Name : %s \n Product Id : %d \n Date Of Expiry : %s ",ProductName,ProductId,DateOfExpiry);
}
}
class Test_Inheritance{
public static void main(String[] args){
AllProducts p1 = new AllProducts();
foodProducts p2 = new foodProducts();
UtilityProducts p3= new UtilityProducts();
p1.Product();
p2.food("21-7-2020");
p3.Utility();
}
}