I'm working on an assignment for school that requires that I:
- Prompt the user to input a string of text
- Determine How many valid words are in that string. Valid words meaning all letters.
- Tell the user how many valid words are in the string.
This program uses the finch robot for output
.
That's pretty much the gist of the assignment but here are the full instructions.
Your Finch has acquired a number of skills this semester. For this skill, write a program that prompts the user for a string of input. The program then determines how many words makeup the input string. The Finch will say the input and tell how many valid words are contained in the string. A valid word must contain all letter characters. If an invalid word is found the Finch will say so and its beak will flash red. Below are examples of input dialog windows.
Bonus: 20 points, allow the user to repeat.
I haven't bothered with any output as of yet. I'm not concerned with that part of the program. What I've done so far is:
split the string into sub strings.
Put each of those sub strings into an ArrayList element,
Then looped through each substring and their individual characters to test to make sure that each character is a letter.
If a substring contains a non-letter character my goal was to remove that entire substring from the ArrayList by using the remove() method.
Unfortunately. I get this error when I compile:
cannot find symbol method remove(int) Line 43
Code Is Below
** I will also attach the file.
Any ideas as to where I went wrong and how I can fix it would be greatly appreciated. Thanks for your time and help.
import finch.*;
import java.util.*;
import javax.swing.JOptionPane;
public class LabAssign9
{
public static void main(final String[] args)
{
// Instantiating the Finch object.
Finch stringFinch = new Finch();
String inputString;
boolean isSubStringAWord;
inputString = JOptionPane.showInputDialog(null, "Enter a string of text.", "Word Count", JOptionPane.PLAIN_MESSAGE);
// Splits inputString into an array of substrings.
String[] subString = inputString.split(" ");
// Loops through each index of the subString array
for(int subStringIndex = 0; subStringIndex < subString.length; subStringIndex++)
{
// Test each individual subString element's characters to see if they are all letters.
for(int i = 0; i < subString[subStringIndex].length(); i++)
{
if(!Character.isLetter(subString[subStringIndex].charAt(i)))
{
// Removes the subString that is not a valid word.
subString.remove(subStringIndex);
// Terminates the loop for this particular subString. It's not neccesary to test any further.
i = subString[subStringIndex].length();
}
}
}
// Always end your program with finch.quit()
stringFinch.quit();
System.exit(0);
}
}
Thanks again for your help.

New Topic/Question
Reply




MultiQuote









|