Java Lesson 08: Multiple objects

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);
        IntArgument argument2 = ArgumentHelper.getArgumentAsInt(1,args);
        printStuff(argument1.getInt());
        printStuff(argument2.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]);
        return new IntArgument(argument);
    }
}

The program is executed as:

java MyClass 2 3

Your work is to create the IntArgument class so it creates an output like:

You specified int: 2
You specified int: 3
Personal tools