Question: Can I get help fixing my code? Public test @Before public void testA() { String s = In addition, it made us tolerant of each

Can I get help fixing my code?

Public test

@Before public void testA() { String s = "In addition, it made us tolerant of each other's " + "yarns--and even convictions. "; bm = new BookMain(); Scanner input = new Scanner(s); bm.analyzeBookText(input); }

@Test public void testTotalCount() { int totalCount = bm.letterData.totalCount(); assertEquals(61, totalCount); }

@Test public void testFreqChar() { assertEquals(4, bm.letterData.freqChar('s')); }

@Test public void testComputeEntropy() { int entropy = bm.letterData.computeEntropy(); assertEquals(3, entropy); }

This is the Code

import java.util.ArrayList;

public class LetterTally {

private static ArrayList text;

public LetterTally() {

text = new ArrayList();

}

public static void setText(ArrayListtext) {

LetterTally.text = text;

}

public int totalCount() {

int count = 0;

for(String s : text) {

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

if(Character.isLetter(s.charAt(i))){

count++;

}

}

}

return count;

}

public int freqChar(char ch) {

int charCount = 0;

for(String s : text) {

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

if(s.charAt(i) == ch){

charCount++;

}

}

}

return charCount;

}

public int computeEntropy() {

double entropy = 0;

double [] p = new double [26];

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

p [i] = ((freqChar((char) 0)) / ((double)totalCount()));

if(p[i] != 0) {

entropy += p[i] * (Math.log(1/p[i]));

}

else

entropy = 0 ;

}

return (int)Math.round(entropy);

}

}

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!