Hi,

 

I'm working on the homework for Lab 1011. My program compiles clean and
the expected results are produced BUT I have extra messages. Can someone
confirm if they are warning messages or is my code wrong? The results
are confusing. 

Thank You!

 

Here is the output of my code:

-------------------------------------------------------

These are the argument names:

Trevor

Karen

Jenna

Brooke

The new name for Trevor is r

The new name for Karen is a

The new name for Jenna is e

Exception in thread "main" java.lang.NullPointerException

The new name for Brooke is r

        at BuiltinClasses.generateNewName(BuiltinClasses.java:52)

        at BuiltinClasses.main(BuiltinClasses.java:46)

Java Result: 1

BUILD SUCCESSFUL (total time: 0 seconds)

---------------------------------------------------------------

 

 

Here is my code:

------------------------------------------------------------------

public class BuiltinClasses {

 

    /**

     * @param args the command line arguments

     */

    public static void main(String[] args) {

       

        // Check for correct command line argument

        if((args.length < 6) || (args.length > 12)) {

            System.out.println("Argument is incorrect.");

            System.out.println("Expecting 3 to 6 names and ages.");

            System.out.println("example: Jane 30 Joe 35 Jill 13");

            System.exit(0);

        }

 

        // Move arguments into an array

        int max = 6;

        int j = 0;

        int k = 0;

        String [] names = new String [max];

        String [] ages = new String [max];

        

        System.out.println("These are the argument names:");

 

        for(int i=0;i < args.length;i++){

            if (i==1 | i==3 | i==5 | i==7 | i==9 | i==11) {

                ages [j] = args[i];

                j++;

            } else {

                names [k] = args[i];

                System.out.println(names[k]);

                k++;

            }

        }

 

        // call method to generate new names

        generateNewName(names);

    }

 

    // Static method to alter name array

    public static void generateNewName(String [] names){

        for(int i=0;i < names.length;i++) {

            char newName = names[i].charAt(1);

            System.out.println("The new name for " + names[i] + " is " +
newName);

        }

    }

}

--------------------------------------------------------------


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to