473,785 Members | 2,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

6 New Member
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 2430
dmjpro
2,476 Top Contributor
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
3048
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 KA}\N{DEVANAGARI VOWEL SIGN AA}\N{DEVANAGARI LETTER KA}" )
34
2155
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: /****************************************/ #include <stdio.h> /* count lines in input */
1
6930
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 with uploaded MS WORD .doc files. Using code like that below: strLine = sr.ReadLine While Not IsNothing(strLine) 'Not eof If Trim(strLine) <> "" Then 'Not blank
4
1816
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 As IO.FileStream Dim sr As IO.StreamReader Dim Result As Integer Try fs = New IO.FileStream( _
3
6355
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, tabs, linefeeds, returns). It will print 3 pieces of information before exit: the first word, the last word, and the number of words read, with one blank in between fields. Input lines of words Output
3
1875
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 represented as '\n' 2. a tab as '\t' 3. a space as ' '
12
10045
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 function "int CountVowels (IN text, OUT Count)". the OUT parameter must be of type counter_t. I've written the code but it doesn't seem to work. Can someone help me please??? ...
2
4132
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 they want until they hit cancel. This is what I have so far: import javax.swing.*; public class Program { //Open Class public static void main(String args) { //Open Main String input, output; //Holds input and output. int aCount = 0,...
6
4288
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 anything to work. Here's what I have so far. #include <iostream> #include <string> #include <cstring> using namespace std;
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9489
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10357
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9959
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.