Skip to content

Commit

Permalink
fix: updated chainload
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex4386 committed Mar 28, 2024
1 parent 0c6843b commit 5df006d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/main/java/me/alex4386/gachon/sw14462/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/alex4386/gachon/sw14462/day08/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/me/alex4386/gachon/sw14462/day08/ex4_7/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
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) {
System.out.println("Enter a score:");
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;
Expand Down Expand Up @@ -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.");
}
}
}

Expand Down

0 comments on commit 5df006d

Please sign in to comment.