diff --git a/src/main/java/me/alex4386/gachon/sw14462/Main.java b/src/main/java/me/alex4386/gachon/sw14462/Main.java index 9783ae5..37ac1e5 100644 --- a/src/main/java/me/alex4386/gachon/sw14462/Main.java +++ b/src/main/java/me/alex4386/gachon/sw14462/Main.java @@ -49,8 +49,7 @@ public static void launchGivenClass(Class klass, String[] args) { try { mainMethod.invoke(null, (Object) args); } catch (InvocationTargetException e) { - System.err.println("Failed to invoke main method."); - e.printStackTrace(); + e.getTargetException().printStackTrace(); return; } catch (IllegalAccessException e) { e.printStackTrace(); diff --git a/src/main/java/me/alex4386/gachon/sw14462/day08/Main.java b/src/main/java/me/alex4386/gachon/sw14462/day08/Main.java index ee18ba4..2bd6b4b 100644 --- a/src/main/java/me/alex4386/gachon/sw14462/day08/Main.java +++ b/src/main/java/me/alex4386/gachon/sw14462/day08/Main.java @@ -5,7 +5,7 @@ public class Main { public static String chainloadTarget = "ex4_7"; - public static void main(String[] args) { + public static void main(String[] args) throws Throwable { String packageName = Main.class.getPackage().getName(); String chainLoadTargetClass = packageName + "." + chainloadTarget + ".Main"; @@ -16,7 +16,7 @@ public static void main(String[] args) { System.err.println("Failed to find the chainload target class."); e.printStackTrace(); } catch (InvocationTargetException e) { - throw new RuntimeException(e); + throw e.getTargetException(); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { diff --git a/src/main/java/me/alex4386/gachon/sw14462/day08/ex4_7/BasketBallGame.java b/src/main/java/me/alex4386/gachon/sw14462/day08/ex4_7/BasketBallGame.java index 00b04f3..9890a79 100644 --- a/src/main/java/me/alex4386/gachon/sw14462/day08/ex4_7/BasketBallGame.java +++ b/src/main/java/me/alex4386/gachon/sw14462/day08/ex4_7/BasketBallGame.java @@ -14,6 +14,10 @@ public void setTeamNames(String team1, String team2) { this.teamName2 = team2; } + public String[] getTeamNames() { + return new String[] { this.teamName1, this.teamName2 }; + } + private void addTeamScore(int teamIdx, int score) { if (teamIdx == 1) { this.teamScore1 += score; diff --git a/src/main/java/me/alex4386/gachon/sw14462/day08/ex4_7/Main.java b/src/main/java/me/alex4386/gachon/sw14462/day08/ex4_7/Main.java index be12898..e586774 100644 --- a/src/main/java/me/alex4386/gachon/sw14462/day08/ex4_7/Main.java +++ b/src/main/java/me/alex4386/gachon/sw14462/day08/ex4_7/Main.java @@ -5,6 +5,8 @@ public class Main { public static void main(String[] args) { BasketBallGame game = new BasketBallGame(); + game.setTeamNames("Cats", "Dogs"); + Scanner scanner = new Scanner(System.in); while (true) { @@ -12,6 +14,10 @@ public static void main(String[] args) { String line = scanner.nextLine(); String[] thisArgs = line.split(" "); + if (thisArgs.length < 2) { + System.err.println("Invalid input!"); + continue; + } char team = thisArgs[0].charAt(0); int score; @@ -40,9 +46,21 @@ public static void main(String[] args) { if (teamIdx > 0) { addScore(game, teamIdx, score); + } else { + System.err.println("Invalid input!"); + continue; } + String[] teams = game.getTeamNames(); + int[] scores = game.getTeamScores(); + System.out.print(teams[0]+" "+scores[0]+", "+teams[1]+" "+scores[1]+"; "); + String winningTeam = game.getWinningTeamName(); + if (winningTeam != null) { + System.out.println(winningTeam+" are winning."); + } else { + System.out.println("Both teams are tied."); + } } }