finalizing terminal version

This commit is contained in:
CT
2026-05-04 10:12:02 -05:00
parent a2949645dd
commit 870f4c6680
7 changed files with 161 additions and 75 deletions

View File

@@ -16,6 +16,7 @@ public class HockeyStats {
}
public static void loadData(String fileName) throws Exception {
players.clear();
File f = new File(fileName);
br = new BufferedReader(new FileReader(f));
st = new StringTokenizer(br.readLine());
@@ -30,12 +31,13 @@ public class HockeyStats {
Integer.parseInt(st.nextToken()), // gamesWon
Integer.parseInt(st.nextToken()))); // gamesLost
}
br.close();
}
public static void saveData(String fileName) throws Exception {
FileWriter fw = new FileWriter(fileName);
String s = players.createSaveData();
fw.write(s);
String save = players.createSaveData();
fw.write(save);
fw.close();
System.out.println("Data saved to " + fileName);
}
@@ -43,21 +45,23 @@ public class HockeyStats {
public static boolean showMenu() throws Exception {
System.out.print(
"""
<---------------------------->
Hockey Stats Manager Menu
<---------------------------->
Hockey Stats Manager Menu
Select an option:
Select an option:
(1) Load Data from Files
(2) Open Data Editor
(3) Open Stats View Menu
(4) Quit
(1) Load Data from Files
(2) Save Data
(3) Open Data Editor
(4) Open Stats View Menu
(5) Quit
<---------------------------->
<---------------------------->
""");
int n;
try {
n = s.nextInt();
s.nextLine();
} catch (Exception e) {
System.out.println("Please choose one of the available menu options!");
return false;
@@ -68,16 +72,19 @@ public class HockeyStats {
loadData("data.txt");
break;
case 2:
saveData("save.txt");
break;
case 3:
while (true) {
if (showDataMenu()) break;
}
break;
case 3:
case 4:
while (true) {
if (showStatsMenu()) break;
}
break;
case 4:
case 5:
System.out.println("Thank you!");
close = true;
break;
@@ -96,9 +103,9 @@ public class HockeyStats {
Select an option:
(1) Print Data
(2) Save Data
(3) null
(1) Add Player
(2) Remove Player
(3) Add Game to Player
(4) Return to main menu
<---------------------------->
@@ -107,25 +114,64 @@ public class HockeyStats {
int k;
try {
k = s.nextInt();
s.nextLine();
} catch (Exception e) {
System.out.println("Please choose one of the available menu options!");
return false;
}
switch (k) {
case 1:
System.out.println(players.toString());
break;
case 2:
saveData("save.txt");
break;
case 3:
break;
case 4:
dataExit = true;
break;
default:
System.out.println("Please choose one of the available menu options!");
break;
try {
switch (k) {
case 1:
System.out.println("Enter The Following Stats:");
System.out.println("\nPlayer Name:");
String newName = s.nextLine();
System.out.println("Player Goals Scored:");
int newGoals = s.nextInt();
System.out.println("Player Assists:");
int newAssists = s.nextInt();
System.out.println("Games Won:");
int newGamesWon = s.nextInt();
System.out.println("Games Lost:");
int newGamesLost = s.nextInt();
s.nextLine();
players.addPlayer(
new HockeyPlayer(newName, newGoals, newAssists, newGamesWon, newGamesLost));
break;
case 2:
System.out.println("Enter the name of the player you want to remove:");
String rmName = s.nextLine();
System.out.println(
players.removePlayer(rmName)
? rmName + " was successfully removed."
: "Player not found.");
break;
case 3:
System.out.println("Enter The Following Stats:");
System.out.println("\nPlayer Name:");
String addName = s.nextLine();
System.out.println("Player Goals Scored:");
int addGoals = s.nextInt();
System.out.println("Player Assists:");
int addAssists = s.nextInt();
s.nextLine();
System.out.println("Games Won? (yes/no)");
boolean addGameWon = s.nextLine().equalsIgnoreCase("yes");
HockeyPlayer found = players.findPlayer(addName);
if (found == null) {
System.out.println("Player not found.");
} else {
found.addGame(addGoals, addAssists, addGameWon);
}
break;
case 4:
dataExit = true;
break;
default:
System.out.println("Please choose one of the available menu options!");
break;
}
} catch (Exception e) {
System.out.println("Please enter the right kind of data");
}
return dataExit;
}
@@ -133,39 +179,66 @@ public class HockeyStats {
public static boolean showStatsMenu() {
System.out.print(
"""
<---------------------------->
Hockey Stats Viewer Menu
<---------------------------->
Hockey Stats Viewer
Select an option:
Select an option:
(1) Stats
(2) Stats
(3) Stats
(4) Stats
(1) Print Data
(2) Find Player
(3) Sort By Name
(4) Sort By Points
(5) Show by Goals > num
(6) Return to Main Menu
<---------------------------->
<---------------------------->
""");
boolean statsExit = false;
int k;
try {
k = s.nextInt();
s.nextLine();
} catch (Exception e) {
System.out.println("Please choose one of the available menu options!");
return false;
}
switch (k) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
statsExit = true;
break;
default:
System.out.println("Please choose one of the available menu options!");
break;
try {
switch (k) {
case 1:
System.out.println(players.toString());
break;
case 2:
System.out.println("Enter the name of the player you want to find:");
String findName = s.nextLine();
HockeyPlayer p = players.findPlayer(findName);
System.out.println(p == null ? "Player not found." : p.toString());
break;
case 3:
players.sortByNames();
System.out.println("Sorted by names");
break;
case 4:
players.sortByPoints();
System.out.println("Sorted by points");
break;
case 5:
System.out.println("Enter the min goals to show:");
int minGoals = s.nextInt();
s.nextLine();
PlayerList pl = players.getPlayersGoalsAbove(minGoals);
System.out.println(pl.toString());
break;
case 6:
statsExit = true;
break;
default:
System.out.println("Please choose one of the available menu options!");
break;
}
} catch (Exception e) {
System.out.println("k = " + k);
System.out.println(e);
System.out.println("Please enter the right kind of data");
}
return statsExit;
}