-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q2.3.txt
114 lines (82 loc) · 1.94 KB
/
Q2.3.txt
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
------------------------TestMed.java................................
import java.util.Scanner;
public class TestMed {
public static void main(String[] args) {
Medicine arr[]=new Medicine[10];
Scanner sc=new Scanner(System.in);
for(int i=0;i<10;i++)
{
System.out.println("What do you want to buy?\n1.Tablet\n2.Ointment\n3.Syrup");
byte n=sc.nextByte();
if(n==1)
{
arr[i]=new Tablet();
}
else if(n==2)
{
arr[i]=new Ointment();
}
else if(n==3)
{
arr[i]=new Syrup();
}
else
System.out.println("INVALID INPUT");
}
System.out.println("---OUTPUT----");
for(int i=0;i<10;i++)
{
arr[i].displayLabel();
}
}
public static void display(Medicine o)
{
if(o instanceof Ointment)
{
Ointment m=(Ointment)o;
System.out.println(m);
m.displayLabel();
}
if(o instanceof Tablet)
{
Tablet m=(Tablet)o;
m.displayLabel();
}
if(o instanceof Syrup)
{
Syrup m=(Syrup)o;
m.displayLabel();
}
}
}
----------------------------Medicine.java---------------------------------------
public class Medicine {
public String displayLabel() {
System.out.println("Name: PHARMA ABC .INC\nAddress: CITY,ROad,ETC");
return null;
}
}
-----------------------------Tablet--------------------------------------
public class Tablet extends Medicine {
public String displayLabel() {
super.displayLabel();
System.out.println("for external use only");
return null;
}
}
------------------------------Syrup--------------------------------------
public class Syrup extends Medicine {
public String displayLabel() {
super.displayLabel();
System.out.println("drink regularly");
return null;
}
}
--------------------------Ointment-------------------------------------
public class Ointment extends Medicine {
public String displayLabel() {
super.displayLabel();
System.out.println("store in cool cool dry place");
return null;
}
}