Question: public class BinaryTree { public User root; public User bestPlatinumUser; //for another method public BinaryTree() { root = null; } /** * Sometimes friendships don't

public class BinaryTree {

public User root; public User bestPlatinumUser; //for another method

public BinaryTree() { root = null; }

/** * Sometimes friendships don't work out. In those cases it's best * to remove that "friend" altogether. This method should remove * all trace of that "friend" in the database (tree). * @param friend the "friend" to remove * @return true if successfully removed, false for all error cases * @throws IllegalArgumentException if "friend" is null */ public boolean deFriend(User friend) throws IllegalArgumentException { if(friend == null) { throw new IllegalArgumentException(); }

return true;

}

I need to write a method that removes a User node from a binary search tree.

below I have attached the User Class --

package Database;

import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date;

/** * Class to represent a PlayStation user. * Created for Data Structures, SP2 2017 * @author James Baumeister * @version 1.0 */ public class User {

private String username; private int level; private double key; private Calendar dob; private ArrayList trophies; private GameList games; private User left; private User right;

public User(String username, Calendar dob, int level) { this.username = username; this.dob = dob; this.level = level; this.key = calculateKey();

}

/** * DO NOT MODIFY THIS METHOD * This method uses the username and level to create a unique key. * As we don't want the username's hash to increase the level, it's first converted * to a floating point, then added to the level. * @return the unique key */ public double calculateKey() { int hash = Math.abs(username.hashCode()); // Calculate number of zeros we need int length = (int)(Math.log10(hash) + 1); // Make a divisor 10^x double divisor = Math.pow(10, length); // Return level.hash return level + hash / divisor; }

public String getUsername() { return username; }

public int getLevel() { return level; }

public double getKey() { return key; }

public Calendar getDob() { return dob; }

public ArrayList getTrophies() { return trophies; } public GameList getGames() { return games; }

public User getLeft() { return left; }

public User getRight() { return right; }

public void setTrophies(ArrayList trophies) { this.trophies = trophies;

}

public void setGames(GameList games) { this.games = games;

}

public void setLeft(User left) { this.left = left; }

public void setRight(User right) { this.right = right; }

@Override public String toString() { Date date = getDob().getTime(); DateFormat dateFormat = new SimpleDateFormat("MMM dd, YYYY"); String strDate = dateFormat.format(date); //return "User: " + getUsername() + " Trophies: " + trophies.toString() + " Games: " + games.toString() //+ " Birth Date: " + strDate; String tempString = ""; tempString += "User: " + getUsername() + " Trophies: "; for(Trophy one_trophy : trophies) { tempString += one_trophy.toString() + " "; } tempString += " Games: " + games.toString() + " " + " Birth Date: " + strDate; return tempString; } //method created to return the number of Platinum trophies for a User public int getPlatinum() { int plat = 0; for(int i = 0; i < trophies.size(); i++) { if(trophies.get(i).getRank() == Trophy.Rank.PLATINUM) { plat++; } } return plat; } //method created to return the number of Gold trophies for a User public int getGold() { int gold = 0; for(int i = 0; i < trophies.size(); i++) { if(trophies.get(i).getRank() == Trophy.Rank.GOLD) { gold++; } } return gold; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!