Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java: ******************Use JUnit Tests to test the program below. The tests that should be used in the JUnit test class are at the bottom.**************************** public

Java:

******************Use JUnit Tests to test the program below. The tests that should be used in the JUnit test class are at the bottom.****************************

public class SplitStats { //-------------------------------------------------------------------- // Declarations //-------------------------------------------------------------------- private String phrase = ""; // phrase entered by user private String testPhrase = ""; // phrase tested by program private String[] split; // split version of the phrase public static final String VOWELS = "aeiouy"; public static final String CONSONANTS = "bcdfghjklmnpqrstvwxz"; public static final String PUNCTUATION = "~`!@#$%^&*()-_=+[{]}\\|;:\'\",<.>/?"; public static final String NUMBERS = "0123456789"; /** * constructor (TokenStats) */ public SplitStats( String incoming ) { phrase = incoming; if ( phrase == null ) phrase = ""; testPhrase = phrase.toLowerCase().trim(); split = testPhrase.split("\\s+"); } // constructor /****************************** public methods ************************/ /** * getNumberOfChars - return the number of characters in the phrase * (not including spaces) * * @return int */ public int getNumberOfChars() { int numChars = 0; for ( String word : split ) numChars += word.length(); return numChars; } // method getNumberOfChars /** * getNumberOfChars (overloaded) - return the number of characters * matching the incoming parameter. * * @param String (input) * @return int */ public int getNumberOfChars( String input ) { int numChars = 0; for ( int i = 0; i < testPhrase.length(); i++ ) if ( input.indexOf(testPhrase.charAt(i)) >= 0 ) numChars++; return numChars; } // method getNumberOfChars (overloaded) /** * getNumberOfWords - return the number of words in the phrase * * @return int */ public int getNumberOfWords() { int numWords = split.length; // had to do this is because split returns 1 element with an // empty String when an empty string is sent if ( numWords == 1 && split[0].length() == 0 ) numWords = 0; return numWords; } // method getNumberOfWords /** * showStats - display statistics */ public void showStats() { for (int i = 0; i < 26; i++) // clear the screen System.out.println(); System.out.print( "For the sentence: "); System.out.println( phrase + " " ); System.out.print( "\tThe number of words is: " ); System.out.println( getNumberOfWords() ); System.out.print( "\tThe number of characters is: " ); System.out.println( getNumberOfChars() ); System.out.print( "\tThe number of vowels is: " ); System.out.println( getNumberOfChars( VOWELS ) ); System.out.print( "\tThe number of consonants is: " ); System.out.println( getNumberOfChars( CONSONANTS ) ); System.out.print( "\tThe number of punctuation marks is: " ); System.out.println( getNumberOfChars( PUNCTUATION ) ); } // method showStats } // class TokenStats 

****************Use these tests for the JUnit Test Class.**************************

public int getNumberOfWords() Send: "I am hungry." Expect: 3 Send: "I am hungry." Expect: 3 Send: "I\tam\hungry." Expect: 3 Send: "" Expect: 0 Send: " " Expect: 0 Send: "\t" Expect: 0 Send: null Expect: 0 public int getNumberOfCharacters() Send: "I am hungry." Expect: 10 Send: "I am hungry." Expect: 10 Send: "I\tam\hungry." Expect: 10 Send: "" Expect: 0 Send: " " Expect: 0 Send: "\t" Expect: 0 Send: null Expect: 0 public int getNumberOfCharacters( String vowels ) Send: "I am hungry." Expect: 4 Send: "I am hungry." Expect: 4 Send: "I\tam\hungry." Expect: 4 Send: "aEiOuY" Expect: 6 Send: "BcDf" Expect: 0 Send: ".,:ae .." Expect: 0 Send: "" Expect: 0 Send: " " Expect: 0 Send: "\t" Expect: 0 Send: null Expect: 0 public int getNumberOfCharacters( String consonants ) Send: "I am hungry." Expect: 5 Send: "I am hungry." Expect: 5 Send: "I\tam\hungry." Expect: 5 Send: "aEiOuY" Expect: 0 Send: "BcDf" Expect: 4 Send: ".,:ae .." Expect: 0 Send: "" Expect: 0 Send: " " Expect: 0 Send: "\t" Expect: 0 Send: null Expect: 0 public int getNumberOfCharacters( String punctuation ) Send: "I am hungry." Expect: 1 Send: "I am hungry." Expect: 1 Send: "I\tam\hungry." Expect: 1 Send: "aEiOuY" Expect: 0 Send: "BcDf" Expect: 0 Send: ".,:ae .." Expect: 5 Send: "" Expect: 0 Send: " " Expect: 0 Send: "\t" Expect: 0 Send: null Expect: 0 

Example:

 /** * Test normal sentence */ @Test public void testGetNumberOfCharsNormalWithSpaces() { int expected = 11; SplitStats stats = new SplitStats( "I am hungery."); assertEquals(expected, stats.getNumberOfChars() ); } /** * Test normal sentence with tabs */ @Test public void testGetNumberOfCharsWithTabs() { int expected = 11; SplitStats stats = new SplitStats( "I\tam\thungery."); assertEquals(expected, stats.getNumberOfChars() ); } 

Im just confused as to what I have to write in the JUnit class.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions