Last active
May 16, 2017 20:06
-
-
Save mkmozgawa/7ca143ec8cde96b3a8090cff66c0a053 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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