Can someone help me with this assignment? Mutual Fund Investor Track App For the next part
Question:
Can someone help me with this assignment?
Mutual Fund Investor Track App
- For the next part of your lab, you will use the BST class you wrote above to create an application that helps users to track investments in mutual funds.
- Using the starter code below, fill in the empty method bodies. Note that you are not allowed to add any additional methods or member variables to these class (including no DecimalFormat member variables) or you will not receive credit for this part of the assignment.
- You may not make anyadditional import statements at the top of any of the below files
This is the BST code I write it.
import java.util.NoSuchElementException;
import java.util.Comparator;
public class BST> {
private class Node {
private T data;
private Node left;
private Node right;
public Node(T data) {
this.data = data;
left = null;
right = null;
}
}
private Node root;
/***CONSTRUCTORS***/
/**
* Default constructor for BST
* sets root to null
*/
public BST() {
root= null;
}
/**
* Copy constructor for BST
* @param bst the BST of which
* to make a copy.
* @param c the way the tree
* is organized
*/
public BST(BST bst) {
if(bst == null) {
root= null;
}
else {
copyHelper(bst.root);
}
}
/**
* Helper method for copy constructor
* @param node the node containing
* data to copy
* @param c the way the tree is organized
* @return
*/
private void copyHelper(Node node) {
if(node == null){
return;
}
else {
insert(node.data, null);
copyHelper(node.left);
copyHelper(node.right);
}
}
/***ACCESSORS***/
/**
* Returns the data stored in the root
* @precondition !isEmpty()
* @return the data stored in the root
* @throws NoSuchElementException when
* precondition is violated
*/
public T getRoot() throws NoSuchElementException{
if(root == null)throw new NoSuchElementException();
return root.data;
}
/**
* Determines whether the tree is empty
* @return whether the tree is empty
*/
public boolean isEmpty() {
return root == null;
}
/**
* Returns the current size of the
* tree (number of nodes)
* @return the size of the tree
*/
public int getSize() {
return getSize(root);
}
/**
* Helper method for the getSize method
* @param node the current node to count
* @return the size of the tree
*/
private int getSize(Node node) {
if(node == null)return 0;
return 1 + getSize(node.left) + getSize(node.right);
}
/**
* Returns the height of tree by
* counting edges.
* @return the height of the tree
*/
public int getHeight() {
return getHeight(root); //remove this. just a default value
}
/**
* Helper method for getHeight method
* @param node the current
* node whose height to count
* @return the height of the tree
*/
private int getHeight(Node node) {
if(node == null)return 0;
int lh = getHeight(node.left);
int rh = getHeight(node.right);
if(lh < rh) return 1+rh;
else return 1 + lh;
}
/**
* Returns the smallest value in the tree
* @precondition !isEmpty()
* @return the smallest value in the tree
* @throws NoSuchElementException when the
* precondition is violated
*/
public T findMin() throws NoSuchElementException{
if(root == null)throw new NoSuchElementException();
return findMin(root);
}
/**
* Recursive helper method to findMin method
* @param node the current node to check
* if it is the smallest
* @return the smallest value in the tree
*/
private T findMin(Node node) {
if(node.left == null)return node.data;
return findMin(node.left);
}
/**
* Returns the largest value in the tree
* @precondition !isEmpty()
* @return the largest value in the tree
* @throws NoSuchElementException when the
* precondition is violated
*/
public T findMax() throws NoSuchElementException{
if(root == null)throw new NoSuchElementException();
return findMax(root);
}
/**
* Helper method to findMax method
* @param node the current node to check
* if it is the largest
* @return the largest value in the tree
*/
private T findMax(Node node) {
if(node.right == null)return node.data;
return findMin(node.right);
}
/**
* Searches for a specified value
* in the tree
* @param data the value to search for
* @param update whether to update the node's
* data with the given data
* @param c the Comparator that indicates the way
* the data in the tree was ordered
* @return the data stored in that Node
* of the tree is found or null otherwise
*/
public T search(T data) {
return search(data.root);
}
/**
* Helper method for the search method
* @param data the data to search for
* @param node the current node to check
* @return the data stored in that Node
* of the tree is found or null otherwise
*/
private T search(T data,Node node) {
if(node == null)return false;
if(node.data == data)return true;
else if(node.data.compareTo(data)<0)return search(data,node.right);
return search(data,node.left);
}
/**
* Determines whether two trees store
* identical data in the same structural
* position in the tree
* @param o another Object
* @return whether the two trees are equal
*/
public boolean equals(Object o) {
Node node = (Node) o;
return equals(root, node);
}
/**
* Helper method for the equals method
* @param node1 the node of the first bst
* @param node2 the node of the second bst
* @return whether the two trees contain
* identical data stored in the same structural
* position inside the trees
*/
private boolean equals(Node node1, Node node2) {
if(node1 == null && node2 == null) return true;
if((node1 != null && node2 == null)||(node1 == null && node2 != null))return false;
if(node1.data.compareTo(node2.data)==0) {
return equals(node1.left, node2.left) && equals(node1.right, node2.right);
}
else return false;
}
/***MUTATORS***/
/**
* Inserts a new node in the tree
* @param data the data to insert
* @param c the Comparator indicating
* how data in the tree is ordered
*/
public void insert(T data) {
insert(node.data);
}
/**
* Helper method to insert
* Inserts a new value in the tree
* @param data the data to insert
* @param node the current node in the
* search for the correct location to insert
* @param c the Comparator indicating
* how data in the tree is ordered
*/
private void insert(T data,Node node) {
if (node == null) {
node = new Node(data);
return;
}
if (data.compareTo(node.data) < 0)
node.left = insert(data , node.left);
else if (data.compareTo(node.data) > 0)
node.right = insert(data ,node.right);
}
/**
* Removes a value from the BST
* @param data the value to remove
* @param c the Comparator indicating
* how data in the tree is organized
* Note: updates nothing when the element
* is not in the tree
*/
public void remove(T data) throws NoSuchElementException{
if(root == null)throw new NoSuchElementException();
remove(data, root);
}
/**
* Helper method to the remove method
* @param data the data to remove
* @param node the current node
* @param c the Comparator indicating how
* data in the tree is organized
* @return an updated reference variable
*/
private Node remove(T data, Node node) {
if (node == null) return node;
if (data .compareTo(node.data)< 0)
node.left = remove(data , node.left);
else if (data .compareTo(node.data)> 0)
node.right = remove(data ,node.right);
else
{
if (node.left == null)
return node.right;
else if (node.right == null)
return node.left;
node.data = findMin(node.right);
node.right = remove(node.data , node.right);
}
return node;
}
/***ADDITONAL OPERATIONS***/
/**
* Prints the data in pre order
* to the console followed by a new
* line
*/
public void preOrderPrint() {
preOrderPrint(root);
System.out.println();
}
/**
* Helper method to preOrderPrint method
* Prints the data in pre order
* to the console followed by a new line
*/
private void preOrderPrint(Node node) {
if(node == null)return;
System.out.print(node.data + " ");
preOrderPrint(node.left);
preOrderPrint(node.right);
}
/**
* Prints the data in sorted order
* to the console followed by a new line
*/
public void inOrderPrint() {
inOrderPrint(root);
System.out.println();
}
/**
* Helper method to inOrderPrint method
* Prints the data in sorted order
* to the console followed by a new line
*/
private void inOrderPrint(Node node) {
if(node == null)return;
inOrderPrint(node.left);
System.out.print(node.data + " ");
inOrderPrint(node.right);
}
/**
* Prints the data in post order
* to the console followed by a new line
*/
public void postOrderPrint() {
postOrderPrint(root);
System.out.println();
}
/**
* Helper method to postOrderPrint method
* Prints the data in post order
* to the console
*/
private void postOrderPrint(Node node) {
if(node == null)return;
postOrderPrint(node.left);
postOrderPrint(node.right);
System.out.print(node.data + " ");
}
}
This is the Mutual Fund code:
import java.text.DecimalFormat;
import java.util.Comparator;
public class MutualFund {
private final String fundName;
private final String ticker;
private double pricePerShare;
/**CONSTRUCTORS*/
/**
* One-argument constructor that assigns
* a fundName and "no ticker" to the ticker
* and -1 to pricePerShare
* @param fundName the fund name
*/
public MutualFund(String fundName) {
//fill in here
}
/**
* Three-argument constructor
* @param fundName the mutual fund name
* @param ticker the ticker symbol
* @param pricePerShare the price per share
*/
public MutualFund(String fundName, String ticker, double pricePerShare) {
//fill in here
}
/**ACCESSORS*/
/**
* Accesses the name of the fund
* @return the fund name
*/
public String getFundName() {
return null;
}
/**
* Accesses the ticker symbol
* @return the ticker symbol
*/
public String getTicker() {
return null;
}
/**
* Accesses the price per share
* @return the price per share
*/
public double getPricePerShare() {
return -1;
}
/**MUTATORS*/
/**
* Updates the share price
* @param pricePerShare the new share price
*/
public void setPricePerShare(double pricePerShare) {
//fill in here
}
/**ADDITIONAL OPERATIONS*/
/**
* Creates a String of the mutual fund information
* in the format:
*
*
*
* Share Price: $
*
*/
@Override public String toString() {
return " ";
}
}
Mutual Fund.txt
Total Bond Market Index Admiral Shares
VBTLX
11.61
Intermediate-Term Investment-Grade
VFICX
10.64
Mid-Cap Index Admiral Shares
VIMAX
230.09
Municipal Money Market
VMSXX
1.00
Total Stock Market Index Admiral Shares
VTSAX
86.49
International Growth
VWIGX
44.20
U.S. Growth
VWUSX
62.41