Connecting Tech Pros Worldwide Forums | Help | Site Map

Counting Vowels and Words with Eclipse

Newbie
 
Join Date: Oct 2008
Posts: 1
#1: Oct 5 '08
Hi! I'm using Eclipse as an IDE, I need to code a program where users enter a string and it computes the count for each vowel, and how many words are in the string. Users can do as many strings as they want until they hit cancel. This is what I have so far:

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. public class Program 
  3. {    //Open Class
  4.     public static void main(String[] args)
  5. {    //Open Main
  6.         String input, output;    //Holds input and output.
  7.         int aCount = 0, eCount = 0, iCount = 0, oCount = 0, uCount = 0,  numLines = 0; //Holds values for entries of respective vowels. All initialized to 0.
  8.         char v = 0;    //v standing for vowel    
  9.  
  10.         String text = null;
  11.         do
  12. {
  13.         input    =    JOptionPane.showInputDialog("Input a line to analyze or Cancel to quit: ");
  14.         input    =    input.toLowerCase();
  15.         input.length();
  16.         numLines    =    numLines + 1;        
  17.         for (int wCount = 0; wCount < text.length(); wCount++)
  18.         v = text.charAt(wCount);
  19.         switch (v)
  20. {//Open switch statement. Braces are not used because there is only 1 corresponding statement per case.
  21.     case 'a':
  22.     aCount = aCount + 1;
  23.     break;
  24.     case 'e':
  25.     eCount = eCount + 1;
  26.     break;
  27.     case 'i':
  28.     iCount = iCount + 1;
  29.     break;
  30.     case 'o':
  31.     oCount = oCount + 1;
  32.     break;
  33.     case 'u':
  34.     uCount = uCount + 1;
  35.     break;
  36.  
  37. }//Close switch statement
  38.     JOptionPane.showMessageDialog(null, "A-Count: " + aCount + "\n" + "E-Count: " + eCount + "\n" 
  39.             + "O-Count" + oCount + "\n" + "U-Count" + uCount + "\n" + "Word Count" + v +  "Line Analisys - name here", text, JOptionPane.PLAIN_MESSAGE);
  40. }//Close do while    
  41.     while (input != null);
  42.  
  43.  
  44. }//Close Main
  45. }//Close Class
  46.  
I have no idea where i'm going wrong, or if i'm even headed in the right direction =\

Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Oct 6 '08

re: Counting Vowels and Words with Eclipse


So what happens when you (attempt to) compile/run your program?
chelvan's Avatar
Member
 
Join Date: Aug 2008
Location: Colombo 06, Srilanka
Posts: 87
#3: Oct 7 '08

re: Counting Vowels and Words with Eclipse


well

your char variable Declaration
Expand|Select|Wrap|Line Numbers
  1. char v='o';
  2.  
you are missing the single code ' ' on the assign value.

then next

your for loop, i thought the switch block should be under the for block. but on your code you missed to define the for block.

then allright.

regards
chel-1
Reply