-
Notifications
You must be signed in to change notification settings - Fork 25
/
SportsCatalogue.java
205 lines (197 loc) · 8.49 KB
/
SportsCatalogue.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package Miscellaneous;
/*There are different types of sports. Some of the are indoors and some are outdoors.
Each has its own properties like, name of the sport, number of players required, time duration (if any),
equipment needed (like ball, bat), country of origin etc. In some games there are subtypes,
like in cricket T20, One day, or Test match. Each sub type will have own properties.
In some cases, they have redefined the rules of its main type.
Like in cricket you have total overs equals to 50 for one day match, 20 for T20 etc.
Some legends are there in each sport. Consider details of some of such players in each type of sports like,
country of origin of that player, name, presently playing or not etc.
Implement the above scenario using java. Use its different features like, class, objects, array of objects,
instance variable hiding, method overloading, inheritance, method overriding etc. wherever needed.
Take help from different keywords like super, this etc.
*/
import java.util.Scanner;
public class SportsCatalogue
{
public static void main(String args[])
{
String Choice = choice();
Object obj = Game_details(Choice);
((Sports) obj).Display();
}
private static String choice()
{
Scanner sc = new Scanner(System.in);
String GameOfChoice = "";
System.out.println("Sports Database : ");
System.out.println("\t1) Indoor games \n\t2) Outdoor games");
System.out.println("Select the type of game you are looking for (1/2): ");
int First_choice = sc.nextInt();
if(First_choice == 1)
{
String[] Games = {"Chess", "Table Tennis", "Carrom", "Snooker"};
System.out.println("Indoor games : ");
System.out.println("\t1)Chess \n\t2)Table Tennis \n\t3)Carrom \n\t4)Snooker");
System.out.println("Select the indoor game you want data for (1/2/3/4) : ");
int Second_choice = (sc.nextInt() - 1);
for(int i=0;i<4;i++)
{
if(Second_choice == i)
{
GameOfChoice = Games[i];
return GameOfChoice;
}
}
System.out.println("INVALID CHOICE");
}
else if(First_choice == 2)
{
String[] Games = {"Football", "Basket Ball", "Cricket", "Tennis"};
System.out.println("Outdoor games : ");
System.out.println("\t1)Football \n\t2)Basket Ball \n\t3)Cricket \n\t4)Tennis");
System.out.println("Select the outdoor game you want data for (1/2/3/4) : ");
int Second_choice = (sc.nextInt() - 1);
for(int i=0;i<4;i++)
{
if(Second_choice == i)
{
GameOfChoice = Games[i];
return GameOfChoice;
}
}
System.out.println("INVALID CHOICE");
}
else
{
System.out.println("ERROR : YOU HAVE ENTERED THE WRONG CHOICE.");
}
return GameOfChoice;
}
private static Sports Game_details(String name)
{
if(name == "Chess")
{
String origin = "India";
String equipments[] = {"Chess board", "Chess coins"};
String players[] = {"Magnus Carlsen", "Viswanathan Anand"};
String playerCountry[] = {"Norway", "India"};
Sports sport = new Sports(name, origin, equipments, players, playerCountry, 2, 120, false, true);
return sport;
}
else if(name == "Table Tennis")
{
String origin = "England";
String equipments[] = {"Racquets", "Table", "Balls"};
String players[] = {"Jan-Ove Waldner", "Ma Long", "Timo Boll"};
String playerCountry[] = {"Swedan", "China", "Germany"};
Sports sport = new Sports(name, origin, equipments, players, playerCountry, 2, 10, false, true);
return sport;
}
else if(name == "Carrom")
{
String origin = "India";
String equipments[] = {"Carrom board", "Carrom Coins", "Striker"};
String players[] = {"Maria Irudayam"};
String playerCountry[] = {"India"};
Sports sport = new Sports(name, origin, equipments, players, playerCountry, 2, 25, false, false);
return sport;
}
else if(name == "Snooker")
{
String origin = "India";
String equipments[] = {"Snooker Table", "Balls", "Cue"};
String players[] = {"Ronnie O'Sullivan", "Stephen Hendry"};
String playerCountry[] = {"England", "Scotland"};
Sports sport = new Sports(name, origin, equipments, players, playerCountry, 2, 2, false, false);
return sport;
}
else if(name == "Football")
{
String origin = "Britain";
String equipments[] = {"Football"};
String players[] = {"Lionel messi", "Cristiano Ronaldo"};
String playerCountry[] = {"Argentina", "Portugal"};
Sports sport = new Sports(name, origin, equipments, players, playerCountry, 11, 45, true, true);
return sport;
}
else if(name == "Basket Ball")
{
String origin = "Massachusetts";
String equipments[] = {"Basket Ball"};
String players[] = {"LeBron James", "Michael Jordan", "Kobe Bryant"};
String playerCountry[] = {"United States", "United States", "United States"};
Sports sport = new Sports(name, origin, equipments, players, playerCountry, 5, 12, false, false);
return sport;
}
else if(name == "Cricket")
{
String origin = "England";
String equipments[] = {"Cricket ball", "Cricket bat", "Wickets"};
String players[] = {"Mahendra Singh Dhoni", "Virat Kohli"};
String playerCountry[] = {"India", "India"};
Sports sport = new Sports(name, origin, equipments, players, playerCountry, 11, 240, true, true);
return sport;
}
else if(name == "Tennis")
{
String origin = "India";
String equipments[] = {"Racquets", "Tennis ball"};
String players[] = {"Roger Federer", "Rafael Nadal"};
String playerCountry[] = {"Switzerland", "Spain"};
Sports sport = new Sports(name, origin, equipments, players, playerCountry, 2, 300, false, true);
return sport;
}
return null;
}
}
class Sports
{
String Name, Origin, Equipments[], PlayersName[], PlayersOrigin[];
int NoOfPlayers, TimeDuration;
boolean SubGame, PlayerStatus;
public Sports(String Name,String Origin,String Equipments[],String PlayersName[],String PlayersOrigin[],
int NoOfPlayers,int TimeDuration,boolean SubGame,boolean PlayerStatus)
{
this.Name = Name;
this.Origin = Origin;
this.Equipments = Equipments;
this.PlayersName = PlayersName;
this.PlayersOrigin = PlayersOrigin;
this.NoOfPlayers = NoOfPlayers;
this.TimeDuration = TimeDuration;
this.SubGame = SubGame;
this.PlayerStatus = PlayerStatus;
}
public void Display()
{
System.out.println("\n\n==========================================================");
System.out.println("Name of the game : \n\t" + this.Name);
System.out.println("\nCountry of origin : \n\t" + this.Origin);
System.out.println("\nEquipments required : ");
for(int i=0;i<this.Equipments.length;i++)
{
System.out.println("\t" + (i+1) + ") " + this.Equipments[i]);
}
System.out.println("\nNumber of players required to play : \n\t" + this.NoOfPlayers + " players");
System.out.println("\nTotal time duration for each game : \n\t" + this.TimeDuration + " minutes");
if(this.SubGame)
{
System.out.println("\nThis sport has various models!");
}
System.out.println("\nLegendry Players In This Game : ");
for(int i=0;i<this.PlayersName.length;i++)
{
System.out.println("\t" + (i+1) + ") " + this.PlayersName[i] + " from " + this.PlayersOrigin[i]);
}
if(this.PlayerStatus)
{
System.out.println("\nAbove legends are still playing the game!");
}
else
{
System.out.println("\nAbove legends have made history and retired.");
}
System.out.println("==========================================================");
}
}