Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

help please

Name: Anonymous 2011-01-13 20:48

trying to finish this lab and keep getting these odd runtime errors, here's my errors
--------------------Configuration: <Default>--------------------
Exception in thread "main" java.lang.NullPointerException
    at Words.setWords(Words.java:32)
    at Words.<init>(Words.java:23)
    at Lab16c.main(Lab16c.java:16)

Process completed.


MAIN CODE

//© A+ Computer Science  -  www.apluscompsci.com
//Name -
//Date -
//Lab  -

import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import static java.lang.System.*;

public class Lab16c
{
    public static void main( String args[] )
    {
        String wordList = "one, two, three, four, five, six, seven, alligator";
        Words test = new Words(wordList);
        out.println(test);
        out.println("word with 2 vowels = "+test.countWordsWithXVowels(2));
        out.println("word with 3 vowels = "+test.countWordsWithXVowels(3));
        out.println("word with 4 vowels = "+test.countWordsWithXVowels(4));
        out.println("word with 2 chars = "+test.countWordsWithXChars(2));
        out.println("word with 4 chars = "+test.countWordsWithXChars(4));
        out.println("word with 5 chars = "+test.countWordsWithXChars(5));
        test.removeWordsWithXChars(3);
        out.println("\nafter removing words with 3 chars \n"+test);
        out.println("\n\n");
        System.out.printLn(test.setWords);


        //more test cases

    }
}

Name: BY THE WAY THIS IS JAVA 2011-01-13 20:49

//© A+ Computer Science  -  www.apluscompsci.com
//Name -
//Date -
//Lab  -

import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import static java.lang.System.*;

public class Words
{
    private ArrayList<String> words;
    String bob;

    public Words()
    {
        setWords("");
    }

    public Words(String wordList)
    {
        setWords(wordList);

    }

    public void setWords(String wordList)
    {
        Scanner sc = new Scanner(wordList);
        while(sc.hasNext())
        {
            words.add(sc.next());
        }
        System.out.println(words);
    }

    public int countWordsWithXChars(int size)
    {
        int count=0;
        for(int i = 0; i < words.size(); i++)
        {
            if(words.get(i).length()==size)
            {
                count++;
            }
        }
        return count;
    }

    public void removeWordsWithXChars(int size)
    {
        for(int i=0; i<words.size(); i++)
        {
            if(words.get(i).length()==size)
            {
                words.remove(i);
            }
        }






    }

    public int countWordsWithXVowels(int numVowels)
    {
        int count=0;
        String str = "";
        for(int i = 0; i < words.size(); i++)
        {
            for ( int b = 0; i < words.get(i).length(); i++)
            {
                str += words.get(i).charAt(b);
                if(str.equalsIgnoreCase("a")||str.equalsIgnoreCase("e")||str.equalsIgnoreCase("i")||str.equalsIgnoreCase("o")||str.equalsIgnoreCase("u"))
                {
                    count++;
                }
                str="";
            }
        }

        return count;
    }

    public String toString()
    {
        return "after re";

    }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List