A simple game player directory

In this exercise you will write a simple program to maintain a list of players of an online game. Your program must read in details of players of an online game and both retrieve and manipulate these details.

Players of an online game are identied by their surname (you may assume this is a single string, in which the rst letter is a capital. E.g. Miller, or Smith), gender (M/F) and high score (an integer between 1 and 100).

(l) Create a text le containing a list of (randomly ordered) players, this le should be called players.txt and contain at least 20 entries in the form: surname (gender) high-score, and each player should be on a separate line, like in the following example:

Miller (F) 17
Smith (M) 5
Jones (F) 27
(etc.)

(2) Create a class Player to represent a player. Each Player object should consist of 3 elds of type String, Boolean and int representing the surname, gender and high-score of the Player. Your class should contain:

  • appropriate constructors.
  • accessor and mutator methods (getters and setters),
  • a toString method
  • any other methods you may require

(3) Create a class Players.java to represent a list of players. Each Players object should consist of a list of players and the current size of the list. Your class should contain;

  • a constructor that creates a list from a text le in which entries are assumed to be of the form described in (I)
  • a method to return the current high score
  • any other methods you may require

Note that the constructor should create a list using an appropriate List. constructor from an implementing class (e.g. an ArrayList, as per the example given in Lecture 1).

(4) Create a class OrqanisePlayers.java which contains a main method and can be used to organize and manipulate the players. All of the functions of this class must use the methods of the Player .java and Players.java classes (i.e. this class should not include any methods itself). You may therefore need to add suitable methods to your other classes to achieve the requirements of this class. Complete this class to:

  • create an object of type Players whose list of players is formed by reading in the list of players from players.txt
  • output the current high score
  • manipulate some of the entries in the list (e.g. change the high-scores, add more entries. remove entries etc.)
  • re-order the list in surname order (in increasing order) and print to standard output
  • re-order the list in high-score order (in descending order) and print to standard output

(Hint: Note that in the arrays section of the lectures we sorted an array using Javas Array class sort method. To sort a List we use a sort method from Javas Collections method.)

When you are sure your program is working correctly, edit your program so that all output is sent to a text le called output.txt. You will be submitting this text le as a demonstration of your pr0grams effectiveness, so make sure that it contains enough evidence that your classes and methods work correctly. For example, an output le for an original list of 3 players:

Miller (F) 17
Smith (M) 5
Jones (F) 27
Adams (M) 10

Would contain (at last) the following information:

The list of players is:
Miller (F) 17
Smith (M) 5
Jones (F) 27
Adams (M) 19

The high score is: 27

The (name)-sorted list is:
Adams (M) 10
Jones (F) 27
Miller (F) 17
Smith (M) 5

The (high-score)-sorted list is:
Jones (F) 27
Miller (F) 17
Adams (M) 10
Smith (M) 5

Using the Java collection classes

This problem should be solved using the List; class, which was introduced in 1 of the course notes. You can nd full documentation of the collection classes at docs.oracle.com/javase/7/does/api.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.