Connecting Tech Pros Worldwide Help | Site Map
Reply
 
LinkBack Thread Tools Search this Thread
  #1  
Old October 5th, 2008, 09:47 PM
Newbie
 
Join Date: Oct 2008
Posts: 1
Default Counting Vowels and Words with Eclipse

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 =\

Last edited by JosAH; October 6th, 2008 at 07:32 AM. Reason: added [code] ... [/code] tags
Reply
  #2  
Old October 6th, 2008, 08:19 AM
Administrator
 
Join Date: Sep 2006
Posts: 11,441
Default

So what happens when you (attempt to) compile/run your program?
Reply
  #3  
Old October 7th, 2008, 05:28 AM
chelvan's Avatar
Member
 
Join Date: Aug 2008
Location: Colombo 06, Srilanka
Age: 23
Posts: 86
Default

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
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.