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

Can I get a hand fixing my code? Public test @Test public void testMultipleSente

ID: 3721705 • Letter: C

Question

Can I get a hand fixing my code?

Public test

@Test
public void testMultipleSentences() {
BookMain bm2 = new BookMain();
String s =
"Theodor Seuss Geisel (March 2, 1904--September 24, 1991) was an American " +
"author, political cartoonist, poet, animator, book publisher, and artist, " +
"best known for authoring more than 60 children's books under the pen name" +
"Doctor Seuss. His work includes several of the most" +
"popular children's books of all time, selling over 600 million copies and " +
"being translated into more than 20 languages by the time of his death.";
Scanner input = new Scanner(s);
bm2.analyzeBookText(input);
assertEquals(2, bm2.sentenceData.getCount());
}

@Test
public void testAveSentenceLength() {
String nAvgSentenceLen = bm.sentenceData.avgSentenceLength();
assertEquals("12.00", nAvgSentenceLen);
}

Here is the code

public String avgSentenceLength() {

boolean isWordChar = false;

int count = 0;

  

String s ="";

  

int charc = 0;

for (String w : text) {

for(int i = 0; i < w.length(); i++) {

if (w.charAt(i) >= 'a' && w.charAt(i) <= 'z' || w.charAt(i) >= 'A' && w.charAt(i) <= 'Z') {

  

charc++;

if (!isWordChar) {

count++;

isWordChar = true;

}

} else {

isWordChar = false;

}

  

double averageLength = charc/count;

  

s = String.format("%.2f", averageLength);

}

}

  

return s;

}

Explanation / Answer

@Test
public void testMultipleSentences() {
BookMain bm2 = new BookMain();
String s =
"Theodor Seuss Geisel (March 2, 1904--September 24, 1991) was an American " +
"author, political cartoonist, poet, animator, book publisher, and artist, " +
"best known for authoring more than 60 children's books under the pen name" +
"Doctor Seuss. His work includes several of the most" +
"popular children's books of all time, selling over 600 million copies and " +
"being translated into more than 20 languages by the time of his death.";
Scanner input = new Scanner(s);
bm2.analyzeBookText(input);
assertEquals(2, bm2.sentenceData.getCount());
}

@Test
public void testAveSentenceLength() {
String nAvgSentenceLen = bm.sentenceData.avgSentenceLength();
assertEquals("12.00", nAvgSentenceLen);
}

Here is the code

public String avgSentenceLength() {

boolean isWordChar = false;

int count = 0;

  

String s ="";

  

int charc = 0;

for (String w : text) {

for(int i = 0; i < w.length(); i++) {

if (w.charAt(i) >= 'a' && w.charAt(i) <= 'z' || w.charAt(i) >= 'A' && w.charAt(i) <= 'Z') {

  

charc++;

if (!isWordChar) {

count++;

isWordChar = true;

}

} else {

isWordChar = false;

}

  

double averageLength = charc/count;

  

s = String.format("%.2f", averageLength);

}

}

return s;

}

The code looks good to me. Could you please explain the issue that you are facing right now. Since, you have not provided the full code, it is difficult for me to compile the code and see the issue myself.

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