Program Help, working with spaces and only letters

I'm writing a program that takes an input string and gets the length and/or gets the number of vowels and consonants in the string. I've gotten it working except for consideration of spaces (which are allowed) and error checking for input other than letters. Here is what I've got so far. ANY suggestions would be greatly appreciated. Thank You
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class LetterStringManip extends JFrame
{//declaring variables
     private JLabel stringOfLettersL, lengthL, lengthRL, vowelsL, vowelsRL, consonantsL, consonantsRL;
       private JTextField stringOfLettersTF;
       private JButton lengthB,vowelB, quitB;
       private LengthButtonHandler lbHandler;
       private VowelButtonHandler vbHandler;
       private QuitButtonHandler qbHandler;
       private static final int WIDTH = 750;
       private static final int HEIGHT = 150;
       public LetterStringManip()
       {// setting up GUI window with buttons
           stringOfLettersL = new JLabel("Enter a String of Letters", SwingConstants.CENTER);
               lengthL = new JLabel("Length of String: ", SwingConstants.CENTER);
               lengthRL = new JLabel("", SwingConstants.LEFT);
               vowelsL = new JLabel("Number of Vowels: ", SwingConstants.CENTER);
               vowelsRL = new JLabel("", SwingConstants.LEFT);
               consonantsL = new JLabel("Number of Consonats: ", SwingConstants.CENTER);
               consonantsRL = new JLabel("", SwingConstants.LEFT);
               stringOfLettersTF = new JTextField(15);
               lengthB = new JButton("Length");
               lbHandler = new LengthButtonHandler();
               lengthB.addActionListener(lbHandler);
               vowelB = new JButton("Vowels");
               vbHandler = new VowelButtonHandler();
               vowelB.addActionListener(vbHandler);
               quitB = new JButton("Quit");
               qbHandler = new QuitButtonHandler();
               quitB.addActionListener(qbHandler);
               setTitle("String Of Letters");//Window title
               Container pane = getContentPane();
               pane.setLayout(new GridLayout(3,4)); //Window layout
               pane.add(stringOfLettersL);
               pane.add(stringOfLettersTF);
               pane.add(lengthL);
               pane.add(lengthRL);
               pane.add(vowelsL);
               pane.add(vowelsRL);
               pane.add(consonantsL);
               pane.add(consonantsRL);
               pane.add(lengthB);
               pane.add(vowelB);
               pane.add(quitB);
               setSize(WIDTH, HEIGHT);
               setVisible(true);
               setDefaultCloseOperation(EXIT_ON_CLOSE);
       }//closes public LetterStringManip()
       private class LengthButtonHandler implements ActionListener
           public void actionPerformed(ActionEvent e)//Length Button is clicked, getLength() method is performed
                  getLength();
               }//closes public void actionPerformed(ActionEvent e)
       }//closes private class LengthButtonHandler implements ActionListener
       private class VowelButtonHandler implements ActionListener
           public void actionPerformed(ActionEvent e)//Vowels Button is clicked, getVowels() method is performed
                  getVowels();
               }//closes public void actionPerformed(ActionEvent e)
       }//closes private class VowelButtonHandler implements ActionListener
       private class QuitButtonHandler implements ActionListener//Quit Buttton is pressed
           public void actionPerformed(ActionEvent e)
                   System.exit(0);
               }//closes public void actionPerformed(ActionEvent e)
       }//closes private class QuitButtonHandler implements ActionListener
                 public void getLength()//gets the length of the string
                   String letString = (stringOfLettersTF.getText());
                   String lengthString;
             int length;
                     length = letString.length();
                     lengthString = Integer.toString(length);
                     lengthRL.setText(lengthString);
                }//closes public void getLength()
                 public void getVowels()//gets the number of vowels in the string
             String letString = (stringOfLettersTF.getText());
                   String vowString;
                     String conString;
             int countVow = 0;
                     int countCon = 0;
                     int i;
                     int length = letString.length();
                     char[] letter = new char[length];
             for (i = 0; i < letString.length(); i++)
                 letter[i] = letString.charAt(i);
                 if (letter=='a' || letter[i]=='e' || letter[i]=='i' || letter[i]=='o' || letter[i]=='u')
countVow++;
                    }//closes for
                    countCon = letString.length() - countVow;
vowString = Integer.toString(countVow);
                    conString = Integer.toString(countCon);
                    vowelsRL.setText(vowString);
                    consonantsRL.setText(conString);
               }//closes public void getVowels()
     public static void main(String[] args)
     LetterStringManip stringObject = new LetterStringManip();
     }// closes public static void main(String[] args)
}//closes public class LetterStringManip extends JFrame

OK, per the instructions above: I will re-post my code that I have now. I have dealt with the space not being counted now, I only need to figure out how to validate my input so that only letters are allowed. If anyone has any suggestions, or can help me out in any way, it'd be great. The suggestions with creating word and sentence objects is still a little beyond what we have gone over thus far in my Java course, I feel like I can almost grasp it to code it, but end up getting really confused. anyways, hear is my 'crude' code so far:
                 public void getLength()
                   String letString = (stringOfLettersTF.getText());
                   String lengthString;
                      int finalLength;
                      int countSpace = 0;
                            int length = letString.length();
                   char[] letter = new char[length];
                    int i;
                             for (i = 0; i < letString.length(); i++)
                                letter[i] = letString.charAt(i);
                                if (letter==' ')
countSpace++;
          finalLength = length - countSpace;
               lengthString = Integer.toString(finalLength);
               lengthRL.setText(lengthString);
               public void getVowels()
String letString = (stringOfLettersTF.getText());
               String vowString;
               String conString;
int countVow = 0;
               int countCon = 0;
               int countSpace = 0;
               int i;
               int length = letString.length();
               char[] letter = new char[length];
for (i = 0; i < letString.length(); i++)
letter[i] = letString.charAt(i);
if (letter[i]=='a' || letter[i]=='e' || letter[i]=='i' || letter[i]=='o' || letter[i]=='u')
countVow++;
               if (letter[i]==' ')
countSpace++;
               countCon = (letString.length() - countVow) - countSpace;
vowString = Integer.toString(countVow);
               conString = Integer.toString(countCon);
               vowelsRL.setText(vowString);
               consonantsRL.setText(conString);

Similar Messages

  • Z77A-G45: XMP works with one and only one ram stick.

    I am having a problem when using XMP with two ram sticks. One and only one ram stick works fine. Here is the story.
    I recently update my build with a set of G.Skill Ripjaws X Series 8GB (2 x 4GB) DDR3 2133. It had one Kingston 4GB 1333 stick in the past.
    The new rams work fine at 1600 if I don't use XMP profile. However, every time when I load XMP, it fails to post. The power goes on for one or two seconds then goes off; then it restarts after a few seconds and fail again. This cycle goes on and on until occasionally it loads the bios and says OC setting failed and click F1 to setup.
    I thought maybe the rams were bad so I unpluged one stick, then it started and worked perfectly. I tried either sticks with all the slots. If only one stick plugs in any slot, it always works with XMP; if both two sticks plug in, whatever combination of slots I use, it failed to start.
    Does anyone have a clue about this?
    Thanks. 

    G.Skill Ripjaws X Series 8GB (2 x 4GB) DDR3 2133
    Due to most likely non standard SPD profiles, they probably need to be manually set up. That or the CPU IMC is weak. Some of the Beta UEFI/BIOS revisions may be available that addresses problems with this RAM. The change logs might indicate such. There are several variations of G45, so make sure the one I linked is the right one;
    https://forum-en.msi.com/index.php?topic=161033.0
     

  • Project Help: Working with slides and video

    I'm trying to create a flash video that will incorporate powerpoint-like slides along with video footage.
    So for instance I will have slide 1 (graphic) - slide 2 (video clip) - slide 3 (text).
    I have used CS4 before for one of my classes but that was a little while ago, and I feel like I'm starting over again.
    When I import the first graphic (.png), is there an option to have it resize to fit the stage?

    I have everything the way I want it except one thing. I have a picture along with text on a slide. I'd like to fly in the picture. It's been a while since I've created motion tweens, can anyone refresh my memory as to how I can have the picture fly in while the text stays put?
    Also, does anyone know if it's possible to do dancing text like the "Saved By the Bell" logo (at the 1:02 mark in the video)?
    http://www.youtube.com/watch?v=kHKvruzbWl4

  • Any free program to work with maps and gprs

    my device didn't have maps icons  
    please any free software to use instead of  the orginal one 

    Hello abualkhair, 
    Welcome to the forums. 
    Have a look at the below link which will help you in getting BlackBerry® Maps installed. 
    BlackBerry Maps 
    -SR
    Come follow your BlackBerry Technical Team on twitter! @BlackBerryHelp
    Be sure to click Kudos! for those who have helped you.Click Solution? for posts that have solved your issue(s)!

  • Dreamweaver Help | Working with Photoshop and Dreamweaver

    This question was posted in response to the following article: http://helpx.adobe.com/dreamweaver/using/photoshop-dreamweaver.html

    Is there a question here?
    Nancy O.

  • Why is my airportxpr only working with Itunes and not with another music program

    why is my airportxpr only working with Itunes and not with another music program??
    I can not select/see other outputs in my sound selector.

    You have not indicated which OS or which music program you have so I have listed a program called Airfoil to try for both Windows and Mac - it may work for you
    for Windows - http://rogueamoeba.com/airfoil/windows/
    for Mac - http://rogueamoeba.com/airfoil/mac/

  • ME293 is a good for programming and work with coreldraw and rhino ?

    ME293 is a good for programming and work with coreldraw and rhino ?

    No there is not. You are correct that Verizon will unlock it for international use, but they will not unlock it for domestic use. That is the way the US carriers work. Fortunately, the LTE enabled phones for Verizon are different. They are unlocked at the start on the GSM side, this was a requirement from the FCC for the allocation of additional LTE frequencies for Verizon. Not sure how long this will last, but your only choice is to use Verizon or to obtain a different phone. That 4S will not work with AT&T.

  • HT4882 hi apple it's kian ! i have mac book air with 10.7.2 version may keyboard light does'nt work with f5 and f6 ! please help me !

    hi apple it's kian ! i have mac book air with 10.7.2 version may keyboard light does'nt work with f5 and f6 ! please help me !

    Hello Kian,
    This may sound silly but if you put your hand over the isight camera, do the lights change on the keyboard?
    Ryan

  • Microphone works with Utube and iTunes but only with earphones for games and Facebook

    Microphone works with Utube and iTunes but only with earphones for games and Facebook, obviously the microphone works but is there something I need to turn or or something to get the external microphone to work for everything?

    Microphone works with Utube and iTunes but only with earphones for games and Facebook, obviously the microphone works but is there something I need to turn or or something to get the external microphone to work for everything?

  • NB200 Windows 7 Fn key not working with ESC and F1 to F8 keys

    I recently bought a Toshiba NB200-136 and everything worked fine.
    Flash cards on top/bottom of the screen work with Space, ESC and F1 to F8 keys, the rest of function buttons work without showing the cards. Lately the cards stopped showing and I cannot use the Fn + Space, ESC, F1-F8 keys (there's just no reaction), though the rest of buttons work with Fn and the LED is always lit when the Fn is pressed.
    I reset Flash Cards, checked and changed their settings few times and they work only if I choose 'Allow the mouse to bring up the cards' option. Even then they don't appear when I press Fn and the functions work only when I click one of the cards.
    The problem appeared after (though I'm not sure if immediately) such situation:
    I clicked Start -> Shut down and closed the lid. When I opened it the next morning I saw an empty list of programs that wouldn't shut down (it happens quite often, but it's off top). I clicked 'Cancel' or 'Force shut down' but it didn't work so I pressed the Power Button for 5 secs to turn the computer off. I noticed the Fn problem after turning it on and it didn't disappear after resets.
    I think the problem appeared before but disappeared after reset so I ignored it.
    I'll be thankful for your help.

    Any time that you force Windows to stop instead of letting it shut down normally (sometimes you have to shut it off), you may have lost clusters of data that interfere with the proper operation of Windows. So I suggest you start up and run scandisk and make sure you check the box for fixing problems. The other box doesn't need to be checked unless you suspect bad sectors on the hard drive and it takes a long time so I recommend only checking the one box for finding and fixing errors.
    Let us know if this worked and the problem is fixed.
    Good luck.

  • What P2P file sharing programs will work with 10.4?

    I tried downloading utorrent, vuze, frostwire and a couple others but they said java had an error or it needed to be at least version 6.  but when i tried to update java it didnt install and jsut stayed at 5.  are there any file sharing programs that work with java 5 and OS X 10.4?  Thanks!

    I'm not on 10.4 at the moment, but there saare APPs that work if you can find them, but if you can upgrade then that would be even better...
    Leopard requirements/10.5.x...
        *  Mac computer with an Intel, PowerPC G5, or PowerPC G4 (867MHz or faster) processor
    minimum system requirements
        * 512MB of memory (I say 1.5GB for PPC at least, 2-3GB minimum for IntelMacs)
        * DVD drive for installation
        * 9GB of available disk space (I say 30GB at least)
    You have to call Apple & likely ask for a Product Specialist to get it, if they still have it! Helps to tell them you have an iPad/iPhone & you can't run 10.6.
    There are workarounds if the 867MHz is the only hangup...
    http://sourceforge.net/projects/leopardassist/
    Snow Leopard/10.6.x Requirements...
    General requirements
       * Mac computer with an Intel processor
        * 1GB of memory (I say 2GB at least)
        * 5GB of available disk space (I say 30GB at least)
        * DVD drive for installation
        * Some features require a compatible Internet service provider; fees may apply.
        * Some features require Apple’s MobileMe service; fees and terms apply.
    Which apps work with Mac OS X 10.6?...
    http://snowleopard.wikidot.com/
    If it's a core Duo & not a Core2Duo, then it'll only run in 32 bit mode.
    Snow Leopard/10.6.x Requirements...
    General requirements
       * Mac computer with an Intel processor
        * 1GB of memory (I say 2GB at least)
        * 5GB of available disk space (I say 30GB at least)
        * DVD drive for installation
        * Some features require a compatible Internet service provider; fees may apply.
        * Some features require Apple’s MobileMe service; fees and terms apply.
    http://store.apple.com/us/browse/home/shop_mac/software/apple?mco=OTY2ODUzOA

  • Working with JTextArea and things like that

    I don't know if this is the right subforum for this.. if not, feel free to move it over to another subforum
    Now i have this exercise.
    I made a file for it , a list.data file. If i run the program, it gives the info in the list.data file in a whole new box.
    So this is in the data file for example:
    Toyota
    Hilux
    Volkswagen
    Rabbit
    Jeep
    Wrangler
    Than if i run the program, it opens a new window and then there is in it:
    Toyota
    Hilux
    Volkswagen
    Rabbit
    Jeep
    Wrangler
    Now the assingment is to create a new car class with the relevant instance variables (just to store the property values i assume). And thereby i have to create relevant methods to access the instance variables. I also have to create a constructor that accepts initial values for the car instance variables.
    The given program is working with two classes. Those are given, i don't need to understand their internal details, says the exercise
    This is a whole new part of Java for me. Can someone give me an example or a hint or something like that?
    Can i just make a new class with in it the car information
    so like:
    import java.util.*;
    public class CarInformation {
        String[] brand = new String[5];
        String[] type  = new String[5];
        public void brands(){
            brand[0]   = "Toyota";
            brand[1]   = "Volkswagen";
            brand[2]   = "Jeep";
        public void types(){
            type[0]    = "Hilux";
            type[1]    = "Rabbit";
            type[2]    = "Wrangler";
        public CarInformation() {
    }If this is right, how can i make the bigger program to read from my new CarInformation class? I think i'm in the dark..

    newbeeinjava wrote:
    Hmm, it is not my intention to get on your nerves..You aren't! Sorry if my post sounded that way.
    My comments are inline:
    import java.util.*;
    public class Car{
        String Brand;
        String Type;
        String Car;    // this isn't needed. the brand and type are the only attributes of a car you need, right?
    // setting the initial values of brand and type is done by the constructor, you don't need these
    //    public void Brands(){
    //        //reserved to store intital markings for Brand variable
    //    public void Types(){
    //        //reserved to store intital markings for Type variable
        // constructors have to have the same name as the class, not CarBrand, or CarType
    /*    public void CarBrand(String Brand) {
            this.Brand = Brand;
    // this is right
        public String getBrand() {
            return Brand;
    /*    public void CarType(String Type) {
            this.Type  = Type;
    // this is right
        public String getType() {
            return Type;
        // change this method name to Car so that it's a constructor. once that's done, it's correct
        public void CarSpecs(String Brand, String Type){  //this one if we can get both Brand and Type in with one method?
            this.Brand = Brand;
            this.Type  = Type;
    // this works too, but you'll want to add a space between the brand and type
            public String getCarSpecs() {
            return Brand + Type;
        public static void main(String[] args) {
    //        new Car().getCarSpecs();
              Car someCar = new Car("honda", "civic");    // create a new car with "honda" and "civic" as the brand and type
              String theSpecs = someCar.getCarSpecs();    // get the specs String from that car
              System.out.println(theSpecs);     // print those specs
    }

  • Anyone know of any greeting card program that works with OS  x?

    anyone know of any greeting card program that works with OS X?

    There is no solution. The Canon UFR2 driver used by the MF series does not work when connected to a Windows share or a wireless print server, including the Airport Extreme or Express. The problem is wholly to do with the way in which Canon has written this driver and therefore the Canon support staff should know this and tell you (although their Mac knowledge in Australia is pitiful and most likely the same in your region).
    If you had a model with Ethernet, then you could connect it to the wireless router and print via IP > LPD. But I know that your MF4150 only has USB as I mate of mine had one and he had exactly the same issue on Tiger, which I documented on the Tiger forum and the Airport printing forum.
    So, don't waste your money on a print server. Get rid of the Canon and get something that will work for all your OS's. If I can suggest, the safest purchase would be to get a model that supports Postscript. While this does cost more, it will help to avoid any limitations that can occur when using a vendors proprietary printer language, like Canon's UFR2.
    Pahu

  • Hello, I have a Mac computer with NVIDIA 750M dedicated graphics card and monitor EIZO but the problem was there when I was working with Windows and Acer monitor. When I open a file from Camera Raw in PS this is smaller than the screen so I double-click w

    Hello, I have a Mac computer with NVIDIA 750M dedicated graphics card and monitor EIZO but the problem was there when I was working with Windows and Acer monitor. When I open a file from Camera Raw in PS this is smaller than the screen so I double-click with the tool "hand" to fit on the screen, but the picture loses sharpness and becomes blurry. If you magnify the image even only slightly with the tool "zoom" the picture comes back clear. In Camera Raw instead is always sharp. I solve the problem by turning off the graphics card in PS but often use plugin that need the graphics card otherwise the processing time is much longer. I ask for help.
    Thanks.

    Hello, I have a Mac computer with NVIDIA 750M dedicated graphics card and monitor EIZO but the problem was there when I was working with Windows and Acer monitor. When I open a file from Camera Raw in PS this is smaller than the screen so I double-click with the tool "hand" to fit on the screen, but the picture loses sharpness and becomes blurry. If you magnify the image even only slightly with the tool "zoom" the picture comes back clear. In Camera Raw instead is always sharp. I solve the problem by turning off the graphics card in PS but often use plugin that need the graphics card otherwise the processing time is much longer. I ask for help.
    Thanks.

  • Device not working with Log and Transfer in FCP

    I am trying to get some footage off my camera into final cut pro, but Final Cut Pro does not recognise my device when I try to use Log & Transfer
    The camera is question is a Cannon Legria FS20, here is a link
    http://www.canon.co.uk/ForHome/Product_Finder/Camcorders/flash_memory/LEGRIAFS20/
    I have looked around but can't seem to find any plug-ins to get it to work with Final Cut Pro, does anyone know any way I can get it to work with Log and Transfer
    Upon inspecting the hard drive, it saves video files in .MOD format with an .MOI file (which i assume is a metadata file
    How can I get it so that my device works with log and transfer?
    Thanks

    Hi -
    I did a little Google searching for information on your camera and it appears that it is a Standard Definition Camera that records in the MPEG-2 format.
    Log and Transfer only works with High Definition material.
    You will need to convert your video clips into a format that will work with FCP.
    I know nothing about working in PAL, but you want to download an free application called MPEG Streamclip from
    http://www.squared5.com/svideo/mpeg-streamclip-mac.html
    This application will convert your MPEG-2 files into a format that you can use directly in FCP.
    Once you have converted the files to Apple DV-PAL, with the correct frame rate (25fps?) and field dominance you can either simply drag the converted files into FCP or import them using File > Import.
    Hope this helps.
    MtD

Maybe you are looking for

  • Automatic payment not working. Why?

    I recently changed my credit card information and it looks like the automatic payment is set up. When I go to my skype number information it shows the updated credit card number. However, I received a notice that my number was being shut down for non

  • FSG column heading customization

    Hi, I am building a business report that gives PTD, YTD for associaited cost centre using FSG based on configured budget(eg MY Budget) and available actuals. "My Budget" is passed as Control Input as there are several types of budget defined. Now wha

  • HRP1000 and HRP1001.

    Hi Gurus- Can anyone give some info on the tables HRP1000 and HRP1001 and important fields in them. Thanks. Ramesh.

  • How to separate perticular column from multidimensionl array

    dear all, i am just reading CAN bus message, problem is that it is accomodated in a 11X7 array which includes frame time stamp, ID, byte length etc but i am interested in CAN data. can anybody tell me how to separate that column from all. i want to r

  • RE: The pits - or case corrosion problems...

    This is in regard to those experiencing problems with case corrosion on their MBP cases (as stated in this and similar threads: http://discussions.apple.com/thread.jspa?threadID=955831&tstart=25). I came across this issue while trying to solve an unr