Java AVL、BST编程作业代写、代做JDK实验
1 IntroductionNeeding a way to manage all your PlayStation friends, you decide to build a backendsystem for adding, removing and maintaining them. The idea is to organiseyour friends so you can search for individuals, search for players who have thesame games as you, determine rankings, and view player information andtrophies. At the same time, you’d like your search queries to be fast, ruling outbasic structures like arrays and linked lists. Deciding that the most importantfactor 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 representinga PlayStation friend. Each friend node contains information about that player,including their username, level and date of birth, along with attached datastructures for their games (single linked-list) and trophies (ArrayList). Inaccordance with the rules of BSTs, each friend has a parent node and two childnodes, 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 forhigher 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 thebasic class structure, ensuring that the test suite is able to run without error. Inpart B you will implement the basic structures needed by User to hold multipleTrophy 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 AVLbalancing. You are free to add your own methods and fields to any of the classesin the Database package, but do not change any existing method prototypes orfield definitions. A testing suite has been provided for you to test the functionalityof your classes. These tests will be used to mark your assignment, but with alteredvalues. This means that you cannot hard-code answers to pass the tests. It issuggested that you complete the assignment in the order outlined in the followingsections. Many of the later-stage classes rely on the correct implementation oftheir dependencies.21.1 Importing into eclipseThe Assignment has been provided as an eclipse project. You just need to importthe project into an existing workspace. See Figure 1 for a visual guide. Make surethat your Java JDK has been set, as well as the two jar files that you need for junitto 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 todownload any other version and doing so may impact the testing environment.Figure 1: Importing the project through File → Import2 Part AIf 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 thetesting classes.32.1 GameThe Game class represents one PlayStation game and includes generalinformation, 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 insection 3 where you will make a single-linked list of games. The Game classrequires the following instance variables:private String name; privateCalendar released; private Gamenext; private int totalTrophies;The toString method should output a string in the following format (quotationmarks included):"Assassin's Creed IV: Black Flag", released on: Nov 29, 2013Hint: A printed Calendar object may not look as you might expect. Take a look atAPIs 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 allocationTest MarkstestConstructor 2toStringTest 3Total: 52.2 TrophyThe Trophy class represents one PlayStation trophy and includes informationabout 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 enumeratorvariables. 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}4private String name; private Rankrank; private Rarity rarity; privateCalendar obtained; private Gamegame;The toString method should output a string in the following format (quotationmarks included):"What Did You Call Me?", rank: BRONZE, rarity: RARE, obtained on: May 04, 2014You should also generate the appropriate accessor and mutator methods.GameTester will assign marks as shown in Table 2:Table 2: TrophyTester mark allocationTest MarkstestConstructor 2toStringTest 3Total: 52.3 UserThe User class represents a PlayStation user and, more generally, a tree node. Mostimportantly when using as a tree node, the class must have a key on which thetree can be ordered. In our case, it is a double named key. This key is a simplefunction based on the combination of a user’s username and level. As levels arewhole numbers and likely not unique, a simple method (see calculateKey snippetbelow) 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’slevel is 3. We do not want to simply add the hash to the level as that would notpreserve the level and would lead to incorrect rankings. Instead, we calculate1234/10000 to get 0.1234. This can then be added to the level. As the usernamesmust be unique, our node keys are now also unique 1 and the user level ispreserved.private double calculateKey() { int hash =Math.abs(username.hashCode()); // Calculatenumber 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; privateArrayList<Trophy> trophies; privateGameList games; private Calendar dob;private User left; private User right;An ArrayList type was chosen for variable trophies as you figured it would be easierto add a new trophy to a list than a standard array, and you probably would mostlyjust traverse the list in order. A GameList object (see section 3) was chosen as thestructure for storing games as a custom single linked-list is more appropriate forwriting reusable methods.The toString method should output a string in the following format:User: PippinTrophies:"War Never Changes", rank: BRONZE, rarity: COMMON, obtained on: Mar 26, 2017"The Nuclear Option", rank: SILVER, rarity: UNCOMMON, obtained on: Mar26, 2017"Prepared for the Future", rank: GOLD, rarity: UNCOMMON, obtained on: Mar 26, 2017"Keep", rank: SILVER, rarity: RARE, obtained on: Mar 26, 2017Games:"Yooka-Laylee", released on: May 11, 2017"Mass Effect Andromeda", released on: Apr 21, 2017"Persona 5", released on: May 04, 2017Birth Date: May 23, 1980You should also generate the appropriate accessor and mutator methods.UserTester will assign marks as shown in Table 3:3 Part BIn this section you will complete the GameList single linked-list for storing Gameobjects.6Table 3: UserTester mark allocationTest MarkstestConstructor 2toStringTest 3Total: 53.1 GameListThe GameList class provides a set of methods used to find Game objects that havebeen linked to form a single-linked list as shown in Figure 2. The head is areference to the first Game node, and each Game stores a reference to the nextGame, or null if the Game is at the end.nullFigure 2: The single-linked list structure built in GameListThe GameList class requires only one instance variable:public Game headThere are a number of methods that you must complete to receive marks forthis section. They can be completed in any order. Your tasks for each method areoutlined 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 shouldsearch for the first available slot, and appropriately set the previous game’s nextvariable. All games must be unique, so you should check that the same game hasnot already been added. Note that the tests require that the provided Game objectis added, not a copy. If the GameList head variable is null, head should be updatedto refer to the new game. If the provided Game object is null, anIllegalArgumentException should be thrown.3.1.2 Game getGame(String name)7getGame should traverse the linked list to find a game with a matching name. Ifthe game cannot be found, the method should return null. If the name provided isnull, 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 argumenta String, the other a Game. Both methods should search the linked list for the targetgame and remove it from the list. You should appropriately set the previousnode’s next variable or set the head variable, if applicable. Both methods shouldthrow 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, 20143.2 GameListTeste4 Part C
In this section you will complete your binary search tree data structure for storingall your friends’ information.4.1 BinaryTreeNow that all the extra setup has been completed, it can all be brought together toform your tree structure. The BinaryTree class provides a set of methods forforming and altering your tree, and a set of methods for querying your tree. Thegoal is to form a tree that adheres to BST rules, resulting in a structure such asshown in Figure 3.Figure 3: The binary search tree structure built in BinaryTreeThe BinaryTree class requires only one instance variable:public User rootThere are a number of methods that you must complete to receive marks forthis section. They can be completed in any order. Your tasks for each method areoutlined in the following sections. Remember that you can add any other methodsyou 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 correctposition to add your new friend. You must also correct set the left, right and parentvariables as applicable. Note that the tests require that you add the provided Userobject, not a copy. If the User key is already present in the tree, this method shouldreturn false. If the User argument is null, this method should throw anIllegalArgumentException. As an example, adding a User with key 6 into Figure 3results in the tree shown in Figure 4.4.1.2 boolean deFriend(User friend)The deFriend method takes as an argument a User to remove from your database.This method should search the tree for the target friend and remove them. Thisshould be achieved by removing all references to the User andFigure 4: The BST after adding a friend with key 6updating the left, right and parent values as applicable. deFriend should return trueif the friend is successfully removed, false if not found or some other error case. Ifthe friend object is null, an IllegalArgumentException should be thrown. As anexample, removing the User with key 4 from Figure 3 results in the tree shown in4.1.3 int countBetterPlayers(User reference)The countBetterPlayers method takes as an argument a User from which youshould search for players with higher rank. This method should search from thereference user and increment a counter of better players to return. You shouldreturn the number of better players, 0 if there are none. Note that a greater keyvalue does not necessarily equal a higher level. If the User argument is null, thismethod should throw an IllegalArgumentException. As an example, using User withkey 7 from Figure 3, this method should return 5.4.1.4 int countWorsePlayers(User reference)The countWorsePlayers method takes as an argument a User from which youshould search for players with lower rank. This method should search from thereference user and increment a counter of worse players to return. You shouldreturn the number of worse players, 0 if there are none. Note that a lower keyvalue does not necessarily equal a lower level. If the User argument is null, thismethod should throw an IllegalArgumentException. As an example, using User withkey 7 from Figure 3, this method should return 4.4.1.5 User mostPlatinums()The mostPlatinums method should search the database and return the player whohas the most platinum-level trophies. If there are multiple players with the samenumber of platinum trophies, gold trophies should be used to break the tie. Ifthere are no users with platinum trophies this method should return null.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 totheir GameList. You should also check that they do not already have that game intheir collection. If either argument is null, this method should throw anIllegalArgumentException.4.1.7 void addTrophy(String username, Trophy trophy)The addTrophy method takes two arguments, a String username and Trophy trophy. Youshould search your database for a matching user and add the new trophy to theirtrophies. You should also check that they do not already have the trophy to be added andthat they do not already have all available trophies for the trophy’s game. If eitherargument 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 useto search for the matching user in the database. You should then increment thatuser’s level by one. If this breaches any BST rules you should make the necessaryadjustments to the tree. As an example, Figure 6 shows an invalid tree after a levelupand Figure 7 shows the correct alteration. If the username argument is null, thismethod should throw an IllegalArgumentException.multiple level-8 users.Figure6:InvalidBSTafterlevel-upapplied. Thekeygeneratorallowsfor12BinaryTreeTester will assign marks as shown in Table 5.5 Part DIn this final section you will implement the AVL tree balancing algorithm. This willgive your tree more efficiency as it will maintain a perfect balance as differentvalues are added.5.1 boolean addAVL(User friend)The addAVL methods takes as an argument a User friend that you should add to thetree. AVL rules should apply, which means that if the tree becomes unbalanced,rotations should be performed to rectify. This excellent visualisation may help youunderstand how to implement any rotations that may be necessary: The problem isbroken 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 rotationsso be sure to test adding descending values. If the friend argument is null, thismethod should throw an IllegalArgumentException.
我们的方向领域:window编程 数值算法 AI人工智能 金融统计 计量分析 大数据 网络编程 WEB编程 通讯编程 游戏编程多媒体linux 外挂编程 程序API图像处理 嵌入式/单片机 数据库编程 控制台 进程与线程 网络安全 汇编语言 硬件编程 软件设计 工程标准规等。其中代写代做编程语言或工具包括但不限于以下范围:
C/C++/C#代写
Java代写
IT代写
Python代写
辅导编程作业
Matlab代写
Haskell代写
Processing代写
Linux环境搭建
Rust代写
Data Structure Assginment 数据结构代写
MIPS代写
Machine Learning 作业 代写
Oracle/SQL/PostgreSQL/Pig 数据库代写/代做/辅导
Web开发、网站开发、网站作业
ASP.NET网站开发
Finance Insurace Statistics统计、回归、迭代
Prolog代写
Computer Computational method代做
因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:
微信:codinghelp