Context: In the UEFA Champions League, the group stage comprises of 32 football
ID: 674688 • Letter: C
Question
Context:
In the UEFA Champions League, the group stage comprises of 32 football clubs.
This year, the following teams have qualified:
Club (Country)
1. Arsenal (ENG)
2. Astana (KAZ)
3. Atlético (ESP)
4. Barcelona (ESP)
5. BATE (BLR)
6. Bayern (GER)
7. Benfica (POR)
8. Chelsea (ENG)
9. CSKA Moskva (RUS)
10. Dinamo Zagreb (CRO)
11. Dynamo Kyiv (UKR)
12. Galatasaray (TUR)
13. Gent (BEL)
14. Juventus (ITA)
15. Leverkusen (GER)
16. Lyon (FRA)
17. M. Tel-Aviv (ISR)
18. Malmö (SWE)
19. Man. City (ENG)
20. Man. United (ENG)
21. Mönchengladbach (GER)
22. Olympiacos (GRE)
23. Paris (FRA)
24. Porto (POR)
25. PSV (NED)
26. Real Madrid (ESP)
27. Roma (ITA)
28. Sevilla (ESP)
29. Shakhtar Donetsk (UKR)
30. Valencia (ESP)
31. Wolfsburg (GER)
32. Zenit (RUS)
Problem Statement:
Our goal is to create a program / website application which randomly generates 8 groups
with 4 teams each.
For e.g., this year’s group stage looks like this:
Rules & Instructions:
Use the list of teams given on Page 1.
Group names will be “Group A”, “Group B”, “Group C” and so on.
A group cannot have more than one team from the same country.
The teams marked in red are domestic league champions. The first team of every
group must be a domestic league champion.
The program should be able to generate a fresh new list each time it is run.
The program should output a list of teams under each group title.
Added points for showing club logos in output.
You are free to use any programming language / stack. Use of database is up to you.
Create and send a ZIP file of your project, with instructions to execute, if any.
Explanation / Answer
public String[][] getGroupOfTeams()
{
String teams={"",""} //Put name of all 32 Teams
String[][] Group=new String[8][4];
int min=0;
int max=31;
for( int i =0; i < 8 ; i++)
{
for(int j=0;j<4;j++)
{
int randomNum = rand.nextInt((max - min) + 1) + min;
Group[i][j]=teams[i];
}
}
return Group;
}
public String[] getDomesticLeagueTeams(String Group[][])
{
String DomesticLeagueTeams[]=new String[8];
for(int i=0;i<8;i++)
DomesticLeagueTeams[i]=Group[i][0];
return DomesticLeagueTeams;
}
public String[][] writeToFileAndCreateZip(String Group[][])
{
PrintWriter out = new PrintWriter(new FileWriter("TeamInfo.txt", true), true);
String heading=" Group-A Group-B Group-C Group-D Group-E Group-F Group-G Group-H ";
out.write(heading);
for( int i =0; i < 8 ; i++)
for(int j=0;j<4;j++)
out.write(Group[i][j]);
out.close();
FileOutputStream fos = new FileOutputStream("TeamInfoZip.zip");
ZipOutputStream zos = new ZipOutputStream(fos);
ZipEntry ze= new ZipEntry("TeamInfo.txt");
zos.putNextEntry(ze);
FileInputStream in = new FileInputStream("TeamInfo.txt");
int len;
while ((len = in.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
in.close();
zos.closeEntry();
zos.close();
}
1. To generate a fresh New List, call getGroupOfTeams() method every time, like this-
String Group[][]=new String[8][4];
Group=getGroupOfTeams();
2. To get Domestic League Champions,
String DomesticLeagueTeams[]=new String[8];
DomesticLeagueTeams=getDomesticLeagueTeams(Group);
3. To write all this data in a file, and Zip it
writeToFileAndCreateZip(Group);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.