473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Counting vowels, lines , and words need some major help thanx

I have gotten the part of counting how many words are in the string, but the vowels just seem alien to me. Ive tried so many things but never close to a correct answer. I know I need to use charAt() and length() some nested loops with do while and for, but cant seem to get headed in the right direction. Also when i click the cancel button my program is suppose to end and tell you how many lines were entered, a count of vowels from all lines ex) A-count : 4 , ... etc. but it gives me a null pointer exception. i am usually very good at figuring out my programming assignments but this one just loses me in every way, prob cause we haven't been taught any of this yet. ANY help is appreciated thank you.

Expand|Select|Wrap|Line Numbers
  1.  
  2.    import javax.swing.*; // gets option pane
  3.  
  4.     public class Program4    {
  5.  
  6.        public static void main (String[] args)  {
  7.  
  8.       // local variables
  9.          String userInput;
  10.          int aCount = 0;
  11.          int eCount = 0;
  12.          int iCount = 0;
  13.          int oCount = 0;
  14.          int uCount = 0;    
  15.             int length;
  16.          int numberOfLines = 0;
  17.          int numberOfChars = 0;
  18.          char specificChar = ' ';
  19.  
  20.  
  21.          do{ 
  22.             userInput = JOptionPane.showInputDialog("Input a line to analyze or Cancel to quit.");
  23.             String[] arr = userInput.split(" ");
  24.             length = arr.length;
  25.  
  26.             for (int j = 0; j < userInput.length(); j++)
  27.                 // loop so many times to collect correct vowels ?      
  28.  
  29.  
  30.                if (userInput == null)
  31.             {
  32.                JOptionPane.showMessageDialog(null, "Summary of all " + length + " analyzed.",
  33.                      "Program 4 Summary (Edward Powers)", JOptionPane.PLAIN_MESSAGE);
  34.                System.exit(0);
  35.             }    
  36.  
  37.             JOptionPane.showMessageDialog(null, "Summary of all " + length + " analyzed.",
  38.                      "Program 4 Summary (Edward Powers)", JOptionPane.PLAIN_MESSAGE);
  39.  
  40.          }while ( userInput != null);
  41.  
  42.       }
  43.  
  44.    }
Oct 4 '07 #1
1 2410
dmjpro
2,476 2GB
I have gotten the part of counting how many words are in the string, but the vowels just seem alien to me. Ive tried so many things but never close to a correct answer. I know I need to use charAt() and length() some nested loops with do while and for, but cant seem to get headed in the right direction. Also when i click the cancel button my program is suppose to end and tell you how many lines were entered, a count of vowels from all lines ex) A-count : 4 , ... etc. but it gives me a null pointer exception. i am usually very good at figuring out my programming assignments but this one just loses me in every way, prob cause we haven't been taught any of this yet. ANY help is appreciated thank you.

Expand|Select|Wrap|Line Numbers
  1.  
  2.    import javax.swing.*; // gets option pane
  3.  
  4.     public class Program4    {
  5.  
  6.        public static void main (String[] args)  {
  7.  
  8.       // local variables
  9.          String userInput;
  10.          int aCount = 0;
  11.          int eCount = 0;
  12.          int iCount = 0;
  13.          int oCount = 0;
  14.          int uCount = 0;    
  15.             int length;
  16.          int numberOfLines = 0;
  17.          int numberOfChars = 0;
  18.          char specificChar = ' ';
  19.  
  20.  
  21.          do{ 
  22.             userInput = JOptionPane.showInputDialog("Input a line to analyze or Cancel to quit.");
  23.             String[] arr = userInput.split(" ");
  24.             length = arr.length;
  25.  
  26.             for (int j = 0; j < userInput.length(); j++)
  27.                 // loop so many times to collect correct vowels ?      
  28.  
  29.  
  30.                if (userInput == null)
  31.             {
  32.                JOptionPane.showMessageDialog(null, "Summary of all " + length + " analyzed.",
  33.                      "Program 4 Summary (Edward Powers)", JOptionPane.PLAIN_MESSAGE);
  34.                System.exit(0);
  35.             }    
  36.  
  37.             JOptionPane.showMessageDialog(null, "Summary of all " + length + " analyzed.",
  38.                      "Program 4 Summary (Edward Powers)", JOptionPane.PLAIN_MESSAGE);
  39.  
  40.          }while ( userInput != null);
  41.  
  42.       }
  43.  
  44.    }

I am not familiar with Swing, so I am giving you a sample code of counting the Vowels & Words in a Line.
Ok! :-)

-----------------------------------------------------------
Don't spoonfeed code.

Jos
Oct 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Srinath Avadhanula | last post by:
Hello, I am wondering if there is a way of counting graphemes (or glyphs) in python. For example, in the following string: u'\u0915\u093e\u0915' ( or equivalently, u"\N{DEVANAGARI LETTER...
34
by: Mo Geffer | last post by:
Greetings: I have a question about the output of the sample program in section 1.5.3 Line Counting of K&R, Second Edition. Here's the program: /****************************************/...
1
by: j | last post by:
Hi, I've been trying to do line/character counts on documents that are being uploaded. As well as the "counting" I also have to remove certain sections from the file. So, firstly I was working...
4
by: Peter | last post by:
Currently I'm using the method below, is there someting more efficient?: Imports System.IO Public Class CountLine Public Shared Function CountLines(ByVal FileName As String) As Integer Dim fs...
3
by: Nhd | last post by:
I have a question which involves reading from cin and counting the number of words read until the end of file(eof). The question is as follows: Words are delimited by white spaces (blanks,...
3
by: arnuld | last post by:
this is an example programme that counts lines, words and characters. i have noticed one thing that this programme counts space, a newline and a tab as a character. i know: 1. a newline is...
12
by: ashpats | last post by:
Hey everyone, I am supposed to write a program that counts the number of vowels in string of characters. It must include "Struct counter_t (it must be declared as in the code i've written)" and...
2
by: Geneses | last post by:
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...
6
by: HypeBeast McStreetwear | last post by:
Hi I'm supposed to be writing a program that counts in a given text, the words that contain at least three different vowels (a,e,i,o,u) For my test run I have to use "unquestionably", but I can't...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.