Question: I've been learning Object-oriented-programming and using Java programming language. This is my input filename game.txt. 4 Malaysia;Japan;Belgium;USA Malaysia;Japan;21-19;21-8;21-17 Malaysia;USA;10-21;21-19;21-11 Malaysia;Belgium;21-9;21-9;21-0 Japan;Belgium;21-10;21-5;19-21 Japan;USA;16-21;21-11;21-18 USA;Belgium;1-21;13-21;16-21 Malaysia;Japan;0-4 Malaysia;USA;1-1

I've been learning Object-oriented-programming and using Java programming language.

This is my input filename game.txt.

4

Malaysia;Japan;Belgium;USA

Malaysia;Japan;21-19;21-8;21-17

Malaysia;USA;10-21;21-19;21-11

Malaysia;Belgium;21-9;21-9;21-0

Japan;Belgium;21-10;21-5;19-21

Japan;USA;16-21;21-11;21-18

USA;Belgium;1-21;13-21;16-21

Malaysia;Japan;0-4

Malaysia;USA;1-1

Malaysia;Belgium;2-11

Japan;Belgium;2-3

Japan;USA;4-2

USA;Belgium;4-5

The first line in this input file consists of the number of countries or also known as team participating in both games.

The second line are the names of these countries.

Then from lines 3 to 8 is the game data for badminton sports and their results that have 3 sets of score.

whereas from line 9 to 14 the game data for soccer sports and also their results.

As you can see, this input file from line 3 and onwards have difference number of items in a line since they are not the same because it depends on the particular sport

This is some additional information, I've been using round robin to determine the number of n teams and then generate m games.

round robin: number of n teams will generate m games 10 teams = 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 = 45 games 9 teams = 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 = 36 games 8 teams = 7 + 6 + 5 + 4 + 3 + 2 + 1 = 28 games 7 teams = 6 + 5 + 4 + 3 + 2 + 1 = 21 games 6 teams = 5 + 4 + 3 + 2 + 1 = 15 5 teams = 4 + 3 + 2 + 1 = 10 4 teams = 3 + 2 + 1 = 6 3 teams = 2 + 1 = 3 2 teams = 1 1 team = 0 0 team = 0 n teams m number of games ------- ----------------- 0 0 1 0 2 1 3 3 4 6 5 10 6 15 7 21 8 28 9 36 10 45 ASSUMPTION: number of teams are limited between 3-10 only
Declare this array of int in the GameTest class. Once you read in the first line the number of teams - let that value be n teams, then we can easily determine the number of games by a simple assignment: //1st line: read n, the number of teams: //declare n soccer and badminton teams Team[] badmintonTeams = new Team[n]; Team[] soccerTeams = new Team[n]; // round-robin number of games int[] numGames = {0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45}; //assign the number of games based on the value of n. int m = numGames[n]; Game[] game = new Game[m]; So my questions are 1) how do I write the code to read in the first line of the number of teams and let that value be n teams, so that I can easily determine the number of games? and 2) how do write the code to read each game data from lines 3 onwards, which can be either badminton or soccer games, whereby each of these two sports have different score format, create that sports object and assign to the game array?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!