Java Lesson 07: New classes

From Erlands Wiki

Jump to: navigation, search

The main class looks as follows:

public class MyClass {
    public static void main(String[] args) {
        IntArgument argument1 = ArgumentHelper.getArgumentAsInt(0,args);
        printStuff(argument1.getInt());
    }
 
    public static void printStuff(int data) {
        System.out.println("You specified int: "+data);
    }
}

The helper class looks as follows:

public class ArgumentHelper {
    public static IntArgument getArgumentAsInt(int argumentNumber, String[] args) {
        int argument = Integer.valueOf(args[argumentNumber]);
    }
}

The program is executed with:

java MyClass 5

Your work is to create the IntArgument class and update the getArgumentAsInt method in the ArgumentHelper class so the program creates an output as the following:

You specified int: 5
Personal tools