-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCovariance.java
More file actions
113 lines (88 loc) · 1.84 KB
/
Covariance.java
File metadata and controls
113 lines (88 loc) · 1.84 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
// Start Code
/*
https://www.hackerrank.com/challenges/java-covariance
*/
class Flower {
// Fields
public String name;
// Constructors
public Flower(){
this("Flower");
}
public Flower(String name){
this.name = name;
}
// Methods
public String whatsYourName(){
return name;
}
}
class Jasmine extends Flower{
// Fields
// Constructors
public Jasmine(){
super("Jasmine");
}
// Methods
}
class Lily extends Flower{
// Fields
// Constructors
public Lily(){
super("Lily");
}
// Methods
}
/*------------------------------------------------------------------*/
class Region {
// Fields
private Flower flower;
// Constructors
public Region(){
this(new Flower());
}
public Region(Flower flower){
this.flower = flower;
}
// Methods
public Flower yourNationalFlower(){
return flower;
}
}
class WestBengal extends Region{
// Fields
// Constructors
public WestBengal(){
super(new Jasmine());
}
// Methods
}
class AndhraPradesh extends Region{
// Fields
// Constructors
public AndhraPradesh(){
super(new Lily());
}
// Methods
}
// End Code
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String s = reader.readLine().trim();
Region region = null;
switch (s) {
case "WestBengal":
region = new WestBengal();
break;
case "AndhraPradesh":
region = new AndhraPradesh();
break;
}
Flower flower = region.yourNationalFlower();
System.out.println(flower.whatsYourName());
}
}