Question: I'm learning Object-Oriented-Programming and using Java language. I've already created 4 class: Team, Game, BadmintonGame and SoccerGame. Below are the codes for each class: class

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

Below are the codes for each class:

class Team

public class Team { protected String nation; // Nation name protected int points; // Points of that nation // Initialise nation name public Team(String nation) { this.nation = nation; } // Returns string containing team information public String toString() { return "Nation: "+nation+" Points: "+points; } }

class Game

public abstract class Game { // Names of nations competing private String nation1; private String nation2; // Initialise names Game(String nation1, String nation2) { this.nation1 = nation1; this.nation2 = nation2; } // Sets names of both nations public void setNames(String nation1, String nation2){ this.nation1 = nation1; this.nation2 = nation2; } // Accessor methods public String Nation1(){ return nation1; } public String Nation2(){ return nation2; } // Returns a string containing names of both nations public String toString() { return "Nation 1: "+nation1+" Nation2: "+nation2; } // abstract method points public abstract int points(String nation); }

class BadmintonGame

public class BadmintonGame extends Game { private String set1, set2, set3; private String score; // Constructor to initialise nations BadmintonGame(String nation1, String nation2) { super(nation1, nation2); } // Constructor to initialise nations, sets and score BadmintonGame(String nation1, String nation2, String set1, String set2, String set3, String score) { super(nation1, nation2); this.set1 = set1; this.set2 = set2; this.set3 = set3; this.score = score; } // Accessor methods public String getSet1() { return set1; } public String getSet2() { return set2; } public String getSet3() { return set3; } public String getScore() { return score; } // Mutator methods public void setSet1(String set) { set1 = set; } public void setSet2(String set) { set2 = set; } public void setSet3(String set) { set3 = set; } public void setScore(String value) { score = value; } // Returns a string containing information about this game public String toString() { return super.toString()+" "+"Set 1: "+set1+" Set 2: "+set2+" Set 3: "+set3+" Score: "+score; } // Points method calculates the points of the given nation public int points(String nation) { int val1 = Integer.parseInt(score.substring(0,1)); int val2 = Integer.parseInt(score.substring(2)); if(nation.equals(super.Nation1())) { // If nation 1 wins if(val1 > val2) return 2; else return 0; } else { // If nation 2 wins if(val1 < val2) return 2; else return 0; } } }

class SoccerGame

public class SoccerGame extends Game { private String score; // Constructor to initialise nations SoccerGame(String nation1, String nation2) { super(nation1, nation2); } // Constructor to initialise nations and score SoccerGame(String nation1, String nation2, String score) { super(nation1, nation2); this.score = score; } // Accessor method public String getScore() { return score; } // Mutator method public void setScore(String value) { score = value; } // Returns a string containing information about this game public String toString() { return super.toString()+" "+"Score: "+score; } // Calculates points for a given nation public int points(String nation) { // for score format 6-3 i.e. goals int idx = score.indexOf('-'); int val1 = Integer.parseInt(score.substring(0, idx)); int val2 = Integer.parseInt(score.substring(idx+1)); if(val1 == val2) return 1; if(nation.equals(super.Nation1())) { // If nation 1 wins if(val1 > val2) return 3; else return 0; } else { // If nation 2 wins if(val1 < val2) return 3; else return 0; } } }

MY QUESTION: So now I need to create class GameTest to test the correctness of these above 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 i need to prompt for the user filenames.

The input filename will be games.txt and the output filenames be badminton.txt and soccer.txt.

The games.txt file first line consists of the number of countries participating. All countries participated in both two sports. The second line are the names of these countries. The rest of 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.

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

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

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:

Team[] badmintonTeams = new Team[n];

Team[] soccerTeams = new Team[n];

Then create an array of Game to hold the games data for both sports. 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.

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!