finalized joptionpane fixed

This commit is contained in:
CT
2026-05-07 18:06:27 -05:00
parent 764b9cd2a0
commit 38f90ec94f
3 changed files with 35 additions and 7 deletions

View File

@@ -116,8 +116,8 @@ public class HockeyPlayer {
public String toString() {
String s =
String.format(
"Name: %s%nGoals: %d\tAssists: %d\tPoints: %d\tPoints Per Game: %.2f%nGames Won: %d"
+ "\tGames Lost: %d\tGames Played: %d%n",
"Name: %s%nGoals: %d Assists: %d Points: %d Points Per Game: %.2f%nGames Won: %d"
+ " Games Lost: %d Games Played: %d%n",
name,
goals,
assists,

View File

@@ -161,8 +161,18 @@ public class HockeyStats {
boolean dataExit = false;
int k;
try {
k = Integer.parseInt(JOptionPane.showInputDialog(menu));
String input = JOptionPane.showInputDialog(menu);
if (input == null) {
throw new NumberFormatException("Cancel or Exit clicked");
}
if (input == "") {
throw new IllegalArgumentException("No input");
}
k = Integer.parseInt(input);
} catch (Exception e) {
if (e instanceof NumberFormatException) {
return true;
}
JOptionPane.showMessageDialog(null, "Please choose one of the available menu options!");
return false;
}
@@ -202,6 +212,7 @@ public class HockeyStats {
case 2:
String rmName =
JOptionPane.showInputDialog(null, "Enter the name of the player you want to remove:");
if (rmName == null) break;
JOptionPane.showMessageDialog(
null,
players.removePlayer(rmName)
@@ -277,8 +288,18 @@ public class HockeyStats {
boolean statsExit = false;
int k;
try {
k = Integer.parseInt(JOptionPane.showInputDialog(menu));
String input = JOptionPane.showInputDialog(menu);
if (input == null) {
throw new NumberFormatException("Cancel or Exit clicked");
}
if (input == "") {
throw new IllegalArgumentException("No input");
}
k = Integer.parseInt(input);
} catch (Exception e) {
if (e instanceof NumberFormatException) {
return true;
}
JOptionPane.showMessageDialog(null, "Please choose one of the available menu options!");
return false;
}
@@ -302,8 +323,15 @@ public class HockeyStats {
JOptionPane.showMessageDialog(null, "Sorted by points");
break;
case 5:
int minGoals =
Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the min goals to show:"));
String minInput = JOptionPane.showInputDialog(null, "Enter the min goals to show:");
if (minInput == null) {
break;
}
if (minInput.equals("")) {
JOptionPane.showMessageDialog(null, "Enter a value");
break;
}
int minGoals = Integer.parseInt(minInput);
PlayerList pl = players.getPlayersGoalsAbove(minGoals);
JOptionPane.showMessageDialog(null, pl.toString());
break;

View File

@@ -49,7 +49,7 @@ public class PlayerList {
public String toString() {
String s = "";
for (HockeyPlayer p : pList) {
s += p.toString();
s += p.toString() + "\n";
}
return s;
}