Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
1.1 Importing into eclipse
The Assignment has been provided as an eclipse project. You just need to import the project into an existing workspace. See Figure 1 for a visual guide. Make sure that your Java JDK has been set, as well as the two jar files that you need for junit to function. This can be found in Project → Properties → Java Build Path → Libraries. The jar files have been provided within the project; there is no need to download any other version and doing so may impact the testing environment.
Figure 1: Importing the project through File → Import
2 Part A
If you run the testing suite, you will be lovingly presented with many errors. Your first task is to complete the class implementations that the tests expect (including instance variables and basic methods) to remove all errors from the testing classes.
2
2.1 Game
The Game class represents one PlayStation game and includes general information, namely the title, release date, and total number of available trophies. In addition, it holds a reference to another Game object. This will be important in section 3 where you will make a single-linked list of games. The Game class requires the following instance variables:
private String name; private Calendar released; private Game next; private int totalTrophies;
The toString method should output a string in the following format (quotation marks included):
“Assassin’s Creed IV: Black Flag”, released on: Nov 29, 2013
Hint: A printed Calendar object may not look as you might expect. Take a look at APIs for java date formatters.
You should also generate the appropriate accessor and mutator methods. GameTester will assign marks as shown in Table 1:
Table 1: GameTester mark allocation
Test Marks
testConstructor 2
toStringTest 3
Total: 5
2.2 Trophy
The Trophy class represents one PlayStation trophy and includes information about its name, date obtained and the game from which it was earnt. Additionally, its rank and rarity values are set from finite options available through enumerator variables. The Trophy class requires the following instance variables:
public enum Rank {
BRONZE, SILVER, GOLD, PLATINUM
} public enum Rarity {
COMMON, UNCOMMON, RARE, VERY_RARE, ULTRA_RARE
}
3
private String name; private Rank rank; private Rarity rarity; private Calendar obtained; private Game game;
The toString method should output a string in the following format (quotation marks included):
“What Did You Call Me?”, rank: BRONZE, rarity: RARE, obtained on: May 04, 2014
You should also generate the appropriate accessor and mutator methods. GameTester will assign marks as shown in Table 2:
Table 2: TrophyTester mark allocation
Test Marks
testConstructor 2
toStringTest 3
Total: 5
2.3 User
The User class represents a PlayStation user and, more generally, a tree node. Most importantly when using as a tree node, the class must have a key on which the tree can be ordered. In our case, it is a double named key. This key is a simple function based on the combination of a user’s username and level. As levels are whole numbers and likely not unique, a simple method (see calculateKey snippet below) is used to combine the two values into one key whilst preserving the level. For example, imagine that the hashcode for username “abc” is 1234 and the user’s level is 3. We do not want to simply add the hash to the level as that would not preserve the level and would lead to incorrect rankings. Instead, we calculate 1234/10000 to get 0.1234. This can then be added to the level. As the usernames must be unique, our node keys are now also unique1 and the user level is preserved.
private double calculateKey() { int hash = Math.abs(username.hashCode()); // Calculate number of zeros we need int length = (int)(Math.log10(hash) + 1);
1 A string’s hash value can never be guaranteed to be unique, but for the purposes of this assignment we will assume them to be.
4
// Make a divisor 10^length double divisor = Math.pow(10, length);
// Return level.hash return level +
hash / divisor;
}
private String username; private int level; private double key; private ArrayList<Trophy> trophies; private GameList games; private Calendar dob; private User left; private User right;
An ArrayList type was chosen for variable trophies as you figured it would be easier to add a new trophy to a list than a standard array, and you probably would mostly just traverse the list in order. A GameList object (see section 3) was chosen as the structure for storing games as a custom single linked-list is more appropriate for writing reusable methods.
The toString method should output a string in the following format: User: Pippin
Trophies:
“War Never Changes”, rank: BRONZE, rarity: COMMON, obtained on: Mar 26, 2017 “The Nuclear Option”, rank: SILVER, rarity: UNCOMMON, obtained on: Mar
26, 2017
“Prepared for the Future”, rank: GOLD, rarity: UNCOMMON, obtained on: Mar 26, 2017 “Keep”, rank: SILVER, rarity: RARE, obtained on: Mar 26, 2017
Games:
“Yooka-Laylee”, released on: May 11, 2017
“Mass Effect Andromeda”, released on: Apr 21, 2017 “Persona 5”, released on: May 04, 2017
Birth Date: May 23, 1980
You should also generate the appropriate accessor and mutator methods. UserTester will assign marks as shown in Table 3:
3 Part B
In this section you will complete the GameList single linked-list for storing Game objects.
5
The User class requires the following instance variables:
Table 3: UserTester mark allocation
Test Marks
testConstructor 2
toStringTest 3
Total: 5
3.1 GameList
The GameList class provides a set of methods used to find Game objects that have been linked to form a single-linked list as shown in Figure 2. The head is a reference to the first Game node, and each Game stores a reference to the next Game, or null if the Game is at the end.
null
Figure 2: The single-linked list structure built in GameList
The GameList class requires only one instance variable:
public Game head
There are a number of methods that you must complete to receive marks for
this section. They can be completed in any order. Your tasks for each method are outlined in the following sections.
3.1.1 void addGame(Game game)
This method should add the provided game to the end of your linked list. It should search for the first available slot, and appropriately set the previous game’s next variable. All games must be unique, so you should check that the same game has not already been added. Note that the tests require that the provided Game object is added, not a copy. If the GameList head variable is null, head should be updated to refer to the new game. If the provided Game object is null, an IllegalArgumentException should be thrown.