Skip to content

Instantly share code, notes, and snippets.

@mkmozgawa
Last active May 16, 2017 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkmozgawa/7ca143ec8cde96b3a8090cff66c0a053 to your computer and use it in GitHub Desktop.
Save mkmozgawa/7ca143ec8cde96b3a8090cff66c0a053 to your computer and use it in GitHub Desktop.
package consoleConverter;
class BaseUninterpretableException extends Exception {
public String getMessage() {
return ("Base uninterpretable");
}
}
public class Runner {
public static int checkBase(String base) throws BaseUninterpretableException {
try {
return Integer.parseInt(base);
} catch (NumberFormatException e) {
throw new BaseUninterpretableException();
}
}
public static void main(String[] args) {
if(args.length != 3) {
System.out.println("Error: Three arguments expected");
System.exit(1);
}
try {
String number = args[0];
int baseFrom = checkBase(args[1]);
int baseTo = checkBase(args[2]);
Converter converter = new Converter(number, baseFrom, baseTo);
System.out.println(converter.convertBase());
} catch (BaseUninterpretableException e) {
System.out.println("Exception: " + e.getMessage());
System.exit(1);
} catch (NumberUninterpretableException e) {
System.out.println("Exception: " + e.getMessage());
System.exit(2);
} catch (BaseOutOfBoundException e) {
System.out.println("Exception: " + e.getMessage());
System.exit(3);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment