Java AVL, BST programming jobs to write, generation of JDK experiment

Source: Internet
Author: User

Java AVL, BST programming jobs to write, generation of JDK experiment
1 Introduction
Needing a-manage all your PlayStation friends, you decide to build a backend
System for adding, removing and maintaining them. The idea was to organise
Your friends so can search for individuals, search for players who has the
Same games as you, determine rankings, and view player information and
Trophies. At the same time, you're d like your search queries to be fast, ruling out
Basic structures like arrays and linked lists. Deciding the most important
Factor for ordering your friends are level, you build a binary search tree (BST)
structure, using the level (actually a function at level, see section 4) as the key.
In this assignment we'll 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). Inch
accordance with the rules of bsts, each friend have a parent node and a child
nodes, left and right. From any one node, all nodes to the left is less (lower level)
And all nodes to the right is 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'll setup the
Basic class structure, ensuring that the test suite are able to run without error. Inch
Part B you'll implement the basic structures needed by User-to-hold multiple
Trophy and Game objects. In the C you'll create your bst-based friend database.
Finally, in part D you'll improve the efficiency of your tree by implementing AVL
Balancing. You is free to add your own methods and fields to any of the classes
The Database package, but does 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'll be used to mark your assignment, and with altered
Values. This means, cannot hard-code answers to pass the tests. It is
Suggested that all 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 have 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 have been set, as well as the and the both jar files that you need for JUnit
to function. This can is 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'll 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'll be important in
Section 3 where you'll 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 would 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 is earnt. Additionally,
Its rank and rarity values is 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 do you call Me?", Rank:bronze, Rarity:rare, obtained On:may 04, 2014
You should also generate the appropriate accessor and mutator methods.
Gametester would 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 has a key on which the
Tree can be ordered. In our case, it is a double named key. This key was a simple
function based on the combination of a user's username and level. As Levels is
Whole numbers and likely not unique, a simple method (see Calculatekey snippet
below) is used to combine the other 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 don't want to simply add the hash to the level as this would not
Preserve the level and would leads to incorrect rankings. Instead, we calculate
1234/10000 to get 0.1234. This can and then is added to the level. As the usernames
Must be unique, we node keys is 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 is guaranteed to being unique, but for the purposes of this assignment we
Would assume them to be.
5
Make a divisor 10^length double divisor =
Math.pow (ten, 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<trophy> Trophies; Private
Gamelist games; Private Calendar DOB;
Private User left; Private User right;
An ArrayList type is chosen for variable trophies as a 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 are 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 would assign marks as shown in Table 3:
3 part B
In this section you'll complete the gamelist a 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 has
been linked to form a single-linked list as shown in Figure 2. The head is a
Reference to the first game node, and all 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 is a number of methods that's must complete to receive marks for
This section. They can completed in any order. Your tasks for each method is
outlined in the following sections.
3.1.1 Void Addgame (game game)
This method should add the provided game to the end of the your linked list. It should
Search for the first available slot, and appropriately set the previous game ' s next
Variable. All games must is unique, so-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 is 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 Gamelistteste

4 Part C
In this section you'll complete your binary search tree data structure for storing
All your friends ' information.
4.1 BinaryTree
Now and all the extra setup have been completed, it can all is 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 this 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 is a number of methods that's must complete to receive marks for
This section. They can completed in any order. Your tasks for each method is
outlined in the following sections. Remember that's can add any other methods
You require, but does not modify existing method signatures.
4.1.1 Boolean befriend (User friend)
The befriend method takes as a 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
Variables as applicable. Note that the tests require so you add the provided User
object, not a copy. If The User key is a already present in the tree, this method should
return FALSE. If the User argument is null, this method should throw an
IllegalArgumentException. As an example, adding a User with key 6 to Figure 3
Results 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. This
should be achieved by removing all references to the User and
Figure 4:the BST after adding a friend with key 6
Updating the left, right and parent values as applicable. Defriend should return True
If the friend is a successfully removed, false if not found or some other error case. If
The friend object is null, a illegalargumentexception should be thrown. As an
example, removing the User with key 4 from 3 results in the tree shown in
4.1.3 int countbetterplayers (User reference)
The Countbetterplayers method takes as a argument a User from which
Should search for players with higher rank. This method should search from the
Reference user and increment a counter of better players to return. You should
Return the number of better players, 0 if there is none. Note that a greater key
Value does not necessarily equal a higher level. If the User argument is null, this
Method should throw an illegalargumentexception. As an example, using the User with
Key 7 from Figure 3, this method should return 5.
4.1.4 int countworseplayers (User reference)
The Countworseplayers method takes as a argument a User from which
Should search for players with lower rank. This method should search from the
Reference user and increment a counter of worse players to return. You should
Return the number of worse players, 0 if there is none. Note that a lower key
Value does not necessarily equal a lower level. If the User argument is null, this
Method should throw an illegalargumentexception. As an example, using the User with
Key 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 who
Have the most platinum-level trophies. If There is multiple players with the same
Number of platinum trophies, gold trophies should is used to break the tie. If
There is no users with Platinum trophies This method should return null.
4.1.6 void Addgame (String username, game game)
The Addgame method takes the arguments, a String username and the game game.
Should search your database for a matching user and add the new game to
Their gamelist. You should also check, that they does not already has that game in
Their collection. If either argument is null, this method should the throw an
IllegalArgumentException.
4.1.7 void Addtrophy (String username, Trophy Trophy)
The Addtrophy method takes the 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 does not already has the trophy to be added and
That they does not already has all available trophies for the trophy ' s game. If either
argument is null and this method should the throw an illegalargumentexception.
4.1.8 void LevelUp (String username)
The LevelUp method takes as an argument a String username so 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 should make the necessary
Adjustments to the tree. As an example, figure 6 shows a 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.
Figure6:invalidbstafterlevel-upapplied. Thekeygeneratorallowsfor
12
Binarytreetester would assign marks as shown in Table 5.
5 part D
In this final section you'll implement the AVL tree balancing algorithm. This would
Give your tree more efficiency as it would 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 so you should add to the
Tree. AVL rules should apply, which means that if the tree becomes unbalanced,
Rotations should is performed to rectify. This excellent visualisation
Understand how to implement "any rotations" may be necessary:the problem are
Broken into stages in the testing file. Tests is only provided for ascending values,
Meaning they only test left rotations. Alternate tests'll also test right rotations
So is sure to test adding descending values. If The friend argument is null, this
Method should throw an illegalargumentexception.

Our Direction field: Window Programming numerical algorithm AI Artificial Intelligence financial statistical Metrology analysis Big Data network programming Web programming Communication Programming game Programming Multimedia Linux plug-in programming API image processing embedded/Microcontroller database programming console process and thread Network security assembly language Hardware programming software Design Engineering Standard Rules. The generation of programming languages or tools including, but not limited to, the following ranges:

C/c++/c# Write

Java Write generation

It generation

Python writes

Tutoring Programming Jobs

The MATLAB Generation writes

Haskell writes

Processing Write

Linux Environment Setup

Rust Generation Write

Data Structure assginment Data structure generation

MIPS Generation Writing

Machine Learning Job Writing

Oracle/sql/postgresql/pig database Generation/Generation/Coaching

Web development, Web development, Web site jobs

Asp. NET Web site development

Finance insurace Statistics Statistics, regression, iteration

Prolog write

Computer Computational Method Generation

Because of professional, so trustworthy. If necessary, please add qq:99515681 or e-mail:[email protected]

: Codinghelp

Java AVL, BST programming jobs to write, generation of JDK experiment

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.