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? the method d

ID: 3727720 • Letter: C

Question

Can someone tell me what is wrong with this code and how to fix it? the method does not output the correct answer

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 longestText() {
}

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

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

/**
* The program read the content from an rich site summary and will print the longest content .
*
* @author: Tanik Saikh

*
*/
public final class longestText {

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

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("Please specify the link here");

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

Please specify the URL : XMLTree xml = new XMLTree1("Specify the URL here");

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