import java.io.*; import java.util.*; public class HockeyStats { static PlayerList players = new PlayerList(); static BufferedReader br; static StringTokenizer st; static Scanner s = new Scanner(System.in); public static void main(String[] args) throws Exception { while (true) { if (showMenu()) break; } s.close(); } public static void loadData(String fileName) throws Exception { File f = new File(fileName); br = new BufferedReader(new FileReader(f)); st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); for (int i = 0; i < n; i++) { st = new StringTokenizer(br.readLine()); players.addPlayer( new HockeyPlayer( st.nextToken() + " " + st.nextToken(), // first + last name Integer.parseInt(st.nextToken()), // goals Integer.parseInt(st.nextToken()), // assists Integer.parseInt(st.nextToken()), // gamesWon Integer.parseInt(st.nextToken()))); // gamesLost } } public static void saveData(String fileName) throws Exception { FileWriter fw = new FileWriter(fileName); String s = players.createSaveData(); fw.write(s); fw.close(); System.out.println("Data saved to " + fileName); } public static boolean showMenu() throws Exception { System.out.print( """ <----------------------------> Hockey Stats Manager Menu Select an option: (1) Load Data from Files (2) Open Data Editor (3) Open Stats View Menu (4) Quit <----------------------------> """); int n; try { n = s.nextInt(); } catch (Exception e) { System.out.println("Please choose one of the available menu options!"); return false; } boolean close = false; switch (n) { case 1: loadData("data.txt"); break; case 2: while (true) { if (showDataMenu()) break; } break; case 3: while (true) { if (showStatsMenu()) break; } break; case 4: System.out.println("Thank you!"); close = true; break; default: System.out.println("Please choose one of the available menu options!"); break; } return close; } public static boolean showDataMenu() throws Exception { System.out.print( """ <----------------------------> Hockey Data Editor Menu Select an option: (1) Print Data (2) Save Data (3) null (4) Return to main menu <----------------------------> """); boolean dataExit = false; int k; try { k = s.nextInt(); } 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; } return dataExit; } public static boolean showStatsMenu() { System.out.print( """ <----------------------------> Hockey Stats Viewer Menu Select an option: (1) Stats (2) Stats (3) Stats (4) Stats <----------------------------> """); boolean statsExit = false; int k; try { k = s.nextInt(); } 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; } return statsExit; } }