Question: Write a Java Program: I need help with fixing my Java code below for the given question, please read the requirements first for a thorough

Write a Java Program:

I need help with fixing my Java code below for the given question, please read the requirements first for a thorough explanation and you will find my code attached

Write a Java Program: I need help with fixing my Java code

The test cases could be found here: http://bit.ly/CS_assn_trees.

These test cases uses random different inputs that check if the program outputs the corresponding values.

Please visit the link for the test cases and also below are some of the cases that I have failed

below for the given question, please read the requirements first for a

thorough explanation and you will find my code attached The test cases

Currently my current code passes 7 out of twenty test cases and must be changed and modified to pass the 20 given test cases. Listed below are my two Java programs TreeBuilder.java and Node.java. If anyone has a better solution and implementation (e.g.: by using just a one java file) please answer the question with your method instead, because the more simple and lesser lines yield better efficiency

Node.java

could be found here: http://bit.ly/CS_assn_trees. These test cases uses random different inputs

TreeBuilder.java

that check if the program outputs the corresponding values. Please visit the

link for the test cases and also below are some of the

cases that I have failed Currently my current code passes 7 out

These are the copyable codes below:

Node.java:

import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Scanner; public class TreeBuilder { static String test = "AAATTCAACT " + "AAATTCCGA " + "AAATCGA " + "AAATA " + "AAAATC " + "AAATTCAACTT " + "AAATT " + "AAATTAAG " + "AAAAGAC " + "AAATTCAAC " + "AAAAGACTGG " + "AAATTC " + "AAATTCAACTA " + "AAATTCAACA " + "AAATTCAACG " + "done"; static ArrayList tree = new ArrayList(); static Node root = new Node("*", null); public static void main(String[] args) { Scanner sc = new Scanner(System.in); String input = ""; String ch = ""; while(!ch.equals("done")) { ch = sc.next(); tree.add(new Node(ch, null)); } tree.remove(tree.size()-1); Collections.sort(tree, NAME); root.children.addAll(tree); tree.clear(); tree.add(root); TreeBuilder T = new TreeBuilder(); T.buildTree(root.children); if(root.children.isEmpty()) System.out.println(root.name); else printTree(tree); } public void buildTree(ArrayList T) { for(int i = 0; i  j && T.get(j).name.startsWith(T.get(i).name)) { T.get(i).children.add(T.get(j)); T.remove(j); Collections.sort(T.get(i).children, NAME); buildTree(T.get(i).children); } } } } public TreeBuilder() { } public static int tabindex = -1; public static void printTree(ArrayList T) { if(!T.isEmpty()) { //print * if(tabindex  n2.name.length()) { return 1; } else { return 0; } } }; public static Comparator NAME = new Comparator( ) { @Override public int compare(Node n1, Node n2) { return n1.name.compareTo(n2.name); } }; } TreeBuilder.java:
import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Scanner; public class TreeBuilder { static String test = "AAATTCAACT " + "AAATTCCGA " + "AAATCGA " + "AAATA " + "AAAATC " + "AAATTCAACTT " + "AAATT " + "AAATTAAG " + "AAAAGAC " + "AAATTCAAC " + "AAAAGACTGG " + "AAATTC " + "AAATTCAACTA " + "AAATTCAACA " + "AAATTCAACG " + "done"; static ArrayList tree = new ArrayList(); static Node root = new Node("*", null); public static void main(String[] args) { Scanner sc = new Scanner(System.in); String input = ""; String ch = ""; while(!ch.equals("done")) { ch = sc.next(); tree.add(new Node(ch, null)); } tree.remove(tree.size()-1); Collections.sort(tree, NAME); root.children.addAll(tree); tree.clear(); tree.add(root); TreeBuilder T = new TreeBuilder(); T.buildTree(root.children); if(root.children.isEmpty()) System.out.println(root.name); else printTree(tree); } public void buildTree(ArrayList T) { for(int i = 0; i  j && T.get(j).name.startsWith(T.get(i).name)) { T.get(i).children.add(T.get(j)); T.remove(j); Collections.sort(T.get(i).children, NAME); buildTree(T.get(i).children); } } } } public TreeBuilder() { } public static int tabindex = -1; public static void printTree(ArrayList T) { if(!T.isEmpty()) { //print * if(tabindex  n2.name.length()) { return 1; } else { return 0; } } }; public static Comparator NAME = new Comparator( ) { @Override public int compare(Node n1, Node n2) { return n1.name.compareTo(n2.name); } }; }

58 public void buildTree (ArrayList T) 59 60 61 62 63 64 65 for(int 0; T.size ( )-1; j && T.get(j).name . startsWith (T.get(1).name)) { children.add (T.get( T.remove(j) Collections.sort(T.get(i).children, NAME) buildTree(T.get(i).children); 67 68 69 70 71 72 73 74 75 76 public TreeBuilder) 78 79 80 public static int tabindex 82 83 84 85 86 877 -1; public static void printTree(ArrayList T) t if(T.isEmpty) //print * if(tabindex T) 59 60 61 62 63 64 65 for(int 0; T.size ( )-1; j && T.get(j).name . startsWith (T.get(1).name)) { children.add (T.get( T.remove(j) Collections.sort(T.get(i).children, NAME) buildTree(T.get(i).children); 67 68 69 70 71 72 73 74 75 76 public TreeBuilder) 78 79 80 public static int tabindex 82 83 84 85 86 877 -1; public static void printTree(ArrayList T) t if(T.isEmpty) //print * if(tabindex

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!