Java Lesson 06: Methods with same name

From Erlands Wiki

Jump to: navigation, search

The helper class still looks as follows:

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

And the main class now looks as follows:

public class MyClass {
    public static void main(String[] args) {
    }
 
    public static void printStuff(int data) {
        System.out.println("You specified int: "+data);
    }
    public static void printStuff(String data) {
        System.out.println("You specified String: "+data);
    }
}

The program is called with:

java MyClass 5 Hello

And your work is to update the main method so it uses the ArgumentHelper class and the printStuff methods to show an output like:

You specified int: 5
You specified String: Hello
Personal tools