Question: I'm learning Object-Oriented-Programming and using Java language. I've already created 4 class: Team, Game, BadmintonGame and SoccerGame. So now I need to create another class

I'm learning Object-Oriented-Programming and using Java language. I've already created 4 class: Team, Game, BadmintonGame and SoccerGame.

So now I need to create another class name as class GameTest.

The GameTest will test the correctness of these classes using text input-output files. It will read the data from a text file and output to two different output files based on the particular sport. Note that the actual input-output filenames may be different, so you need to prompt for the user filenames and not hardcoded all the filenames in your program. For the sake of understanding, let the input filename be games.txt and the output filenames be badminton.txt and soccer.txt.

The following is the sample data set of 6 soccer and badminton games each for four countries in games.txt file

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 games.txt file first line consists of the number of countries participating. All countries participated in both two sports which are badminton and soccer.

The second line are the names of these countries.

The input file consist of the games and their results. Note that the number of items in a line are not the same because it depends on the particular sport.

Line 3 to 8 is the results of badminton games with 3 sets of score.

Line 9 to 14 is the result for soccer game.

For each sport, create an array of Team to hold the data for these countries. So you will have two arrays of Team one for the list of badminton teams sand the other for the list of soccer teams:

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]; Then 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. From there, create objects of either BadmintonGame or SoccerGame and calculate and total the points for each team in each sport.

The badminton.txt file will store the results of each badminton game as well as print the winner of the badminton sport the country and the total points scored.

The soccer.txt file will store the results of each soccer game as well as print the winner of the soccer sport the country and the total points scored.

NOTE THAT I'VE ALREADY use The method points to calculates ONLY the number of points for each nation1 and nation2, for both game in BadmintonGame and SoccerGame.

THE OUTPUT FILES SHOULD BE LOOKED LIKE THIS:

badminton.txt

nation1 nation2 set 1 set 2 set 3

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

The winner of badminton sport is Team Malaysia with total 120 points.

soccer.txt

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 winner of soccer sport is Belgium with total 17 points.

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!