Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone tell me what is wrong with this code and how to fix it? import compo

ID: 3727488 • Letter: C

Question

Can someone tell me what is wrong with this code and how to fix it?

import components.simplereader.SimpleReader;
import components.simplereader.SimpleReader1L;
import components.simplewriter.SimpleWriter;
import components.simplewriter.SimpleWriter1L;
import components.xmltree.XMLTree;
import components.xmltree.XMLTree1;

/**
* Put a short phrase describing the program here.
*
* @author Put your name here
*
*/
public final class longestText {

/**
* Private constructor so this utility class cannot be instantiated.
*/
private LeafCount() {
}

private static String longestText(XMLTree t) {

String longest = "";
int max = 0; int count = 0;
if (t.isTag()) { for (int i = 0; i < t.numberOfChildren(); i++) {
longest = longestText(t.child(i));
if (!t.child(i).isTag()) {
count = t.child(i).label().length();
if (count > longest.length()) {
longest = t.child(i).label();

}

}

}

}

return longest; }

public static void main(String[] args) {
SimpleReader in = new SimpleReader1L();
SimpleWriter out = new SimpleWriter1L();

out.println("Please enter an RSS link: ");
String web = in.nextLine();

XMLTree xml = new XMLTree1(web);

String word = longestText(xml);
out.println(word);
  
in.close();
out.close();
}





Explanation / Answer

// you forgot to write the return type of the function leafCount

import components.simplereader.SimpleReader;
import components.simplereader.SimpleReader1L;
import components.simplewriter.SimpleWriter;
import components.simplewriter.SimpleWriter1L;
import components.xmltree.XMLTree;
import components.xmltree.XMLTree1;

/**
* Put a short phrase describing the program here.
*
* @author Put your name here
*
*/
public final class longestText {

/**
* Private constructor so this utility class cannot be instantiated.
*/
private int LeafCount() {
// you forgot to write a return type for this function
// it seems, you are using this function for counting the number of leafs
// so, I'm making it's return type to int
// you can write your code here
// remaining code is working
}

private static String longestText(XMLTree t) {
String longest = "";
int max = 0; int count = 0;
if (t.isTag())
{
for (int i = 0; i < t.numberOfChildren(); i++)
{
longest = longestText(t.child(i));
if (!t.child(i).isTag()) {
count = t.child(i).label().length();
if (count > longest.length()) {
longest = t.child(i).label();
}
}
}
}
return longest;
}

public static void main(String[] args) {
SimpleReader in = new SimpleReader1L();
SimpleWriter out = new SimpleWriter1L();

out.println("Please enter an RSS link: ");
String web = in.nextLine();

XMLTree xml = new XMLTree1(web);

String word = longestText(xml);
out.println(word);
  
in.close();
out.close();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote