首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
program代做、代写Java程序设计
项目预算:
开发周期:
发布时间:
要求地区:
Data Structures: Assignment 2
My PlayStation Friends
SP2, 2018
James Baumeister
March 2018
1 Introduction
Needing a way to manage all your PlayStation friends, you decide to build a backend system for adding, removing and maintaining them. The idea is to organise
your friends so you can search for individuals, search for players who have the
same games as you, determine rankings, and view player information and
trophies. At the same time, you’d like your search queries to be fast, ruling out
basic structures like arrays and linked lists. Deciding that the most important
factor for ordering your friends is level, you build a binary search tree (BST)
structure, using the level (actually a function on level, see section 4) as the key.
In this assignment we will build a BST structure, with each node representing
a PlayStation friend. Each friend node contains information about that player,
including their username, level and date of birth, along with attached data
structures for their games (single linked-list) and trophies (ArrayList). In
accordance with the rules of BSTs, each friend has a parent node and two child
nodes, left and right. From any one node, all nodes to the left are less (lower level)
and all nodes to the right are greater (higher level). Due to this, searching for
higher or lower-levelled players is, on average, a O(logn) process.
This assignment consists of a number of parts. In part A you will setup the
basic class structure, ensuring that the test suite is able to run without error. In
part B you will implement the basic structures needed by User to hold multiple
Trophy and Game objects. In part C you will create your BST-based friend database.
Finally, in part D you will improve the efficiency of your tree by implementing AVL
balancing. You are free to add your own methods and fields to any of the classes
in the Database package, but do not change any existing method prototypes or
field definitions. A testing suite has been provided for you to test the functionality
of your classes. These tests will be used to mark your assignment, but with altered
values. This means that you cannot hard-code answers to pass the tests. It is
suggested that you complete the assignment in the order outlined in the following
sections. Many of the later-stage classes rely on the correct implementation of
their dependencies.
2
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.
3
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
}
4
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 unique 1 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.
5
// Make a divisor 10^length double divisor =
Math.pow(10, length);
// Return level.hash return level +
hash / divisor;
}
The User class requires the following instance variables:
private String username; private int level;
private double key; private
ArrayList
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.
6
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.
3.1.2 Game getGame(String name)
7
getGame should traverse the linked list to find a game with a matching name. If
the game cannot be found, the method should return null. If the name provided is
null, the method should throw an IllegalArgumentException.
3.1.3 void removeGame(String name) — void removeGame(Game game)
There are two overloaded removeGame methods with one taking as an argument
a String, the other a Game. Both methods should search the linked list for the target
game and remove it from the list. You should appropriately set the previous
node’s next variable or set the head variable, if applicable. Both methods should
throw an IllegalArgumentException if their argument is null.
3.1.4 String toString()
This method should output a string in the following format:
"Assassin's Creed IV: Black Flag", released on: Nov 29, 2013
"Child of Light", released on: May 01, 2014
3.2 GameListTester
GameListTester will assign marks as shown in Table 4:
Table 4: GameListTester mark allocation
Test Marks
getGameNullArg 1
getGame 2
addGame 2
addGameExists 1
addGameNullArg 1
removeGameNullArg 1
removeGameString 2
removeGameObject 2
8
toStringTest 3
Total: 15
4 Part C
In this section you will complete your binary search tree data structure for storing
all your friends’ information.
4.1 BinaryTree
Now that all the extra setup has been completed, it can all be brought together to
form your tree structure. The BinaryTree class provides a set of methods for
forming and altering your tree, and a set of methods for querying your tree. The
goal is to form a tree that adheres to BST rules, resulting in a structure such as
shown in Figure 3.
Figure 3: The binary search tree structure built in BinaryTree
The BinaryTree class requires only one instance variable:
public User root
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. Remember that you can add any other methods
you require, but do not modify existing method signatures.
4.1.1 boolean beFriend(User friend)
The beFriend method takes as an argument a new User to add to your database.
Adhering to the rules of BSTs, you should traverse the tree and find the correct
position to add your new friend. You must also correct set the left, right and parent
4.1.6 void addGame(String username, Game game)
The addGame method takes two arguments, a String username and Game game.
You should search your database for a matching user and add the new game to
their GameList. You should also check that they do not already have that game in
their collection. If either argument is null, this method should throw an
IllegalArgumentException.
4.1.7 void addTrophy(String username, Trophy trophy)
The addTrophy method takes two arguments, a String username and Trophy trophy. You
should search your database for a matching user and add the new trophy to their
trophies. You should also check that they do not already have the trophy to be added and
that they do not already have all available trophies for the trophy’s game. If either
argument is null, this method should throw an IllegalArgumentException.
4.1.8 void levelUp(String username)
The levelUp method takes as an argument a String username that you should use
to search for the matching user in the database. You should then increment that
user’s level by one. If this breaches any BST rules you should make the necessary
adjustments to the tree. As an example, Figure 6 shows an invalid tree after a levelup and Figure 7 shows the correct alteration. If the username argument is null, this
method should throw an IllegalArgumentException.
multiple level-8 users.
4.2 BinaryTreeTester
(Dulcinea)
(Sophronia) (Medraut)
(Pippin)
(Lunete)
(Astaroth) (Guiomar)
Figure6:InvalidBSTafterlevel-upapplied. Thekeygeneratorallowsfor
12
BinaryTreeTester will assign marks as shown in Table 5.
5 Part D
In this final section you will implement the AVL tree balancing algorithm. This will
give your tree more efficiency as it will maintain a perfect balance as different
values are added.
5.1 boolean addAVL(User friend)
The addAVL methods takes as an argument a User friend that you should add to the
tree. AVL rules should apply, which means that if the tree becomes unbalanced,
rotations should be performed to rectify. This excellent visualisation may help you
understand how to implement any rotations that may be necessary:
https://www.cs.usfca.edu/ galles/visualization/AVLtree.html The problem is
broken into stages in the testing file. Tests are only provided for ascending values,
meaning they only test left rotations. Alternate tests will also test right rotations
so be sure to test adding descending values. If the friend argument is null, this
method should throw an IllegalArgumentException.
5.2 AVLTester
Marks for AVLTest will be assigned as shown in Table 6.
Figure 7: Correct operations applied after level-up to preserve BST structure.
Table 5: BinaryTreeTester mark allocation
(Cosette) (Haidee)
(Nelida)
User
key = 3.20
(Dulcinea)
(Sophronia)
(Medraut)
(Pippin)
(Lunete)
(Astaroth) (Guiomar)
13
Test Marks
beFriendNullArg 1
beFriendDuplicate 1
beFriend 6
deFriendNullArg 1
deFriendNonExistent 1
deFriend 7
countBetterPlayersNullArg 1
countBetterPlayersNonExistent 1
countBetterPlayers 4
countWorsePlayersNullArg 1
countWorsePlayersNonExistent 1
countWorsePlayers 4
mostPlatinums 4
addGameNullArg 1
addGame 4
addTrophyNullArg 1
addTrophy 4
levelUpNullArgs 1
levelUp 7
toStringTest 3
Total: 54
14
Table 6: avlTester mark allocation
Test Marks
avlStage1 6
avlStage2 5
avlStage3 5
Total: 16
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!