java - Calling other classes using command line arguments? -
i writing program use 2 command line arguments - first 1 choose 1 of 3 support classes, , second int input value.
this has me confused on many levels, main thing i'd learn how refer to/call support method app class.
so far, plan to: use if-else (that is, if args[0] = 1 this&that; if args[0] = 2 this&that, etc)
am on right track? @ moment, don't know "this&that" be. i'm guessing statement call other classes - how that?
i teaching myself, , it's not easy :)
thank time , knowledge!
if support classes all take integer, make them implement same interface appropriate method. use of various means create instance of class based on first command-line argument:
- you use
class.forname(),class.newinstance() - you use switch statement in java 7
- you use if/else statements (remembering check equality using
equalsrather==
once you've got instance of implementation of interface, can parse second command line argument using integer.parseint or decimalformat, , call method on interface.
Comments
Post a Comment