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

2
.gitignore vendored
View File

@@ -1 +1,3 @@
*.class
save.txt
data.txt

View File

@@ -49,14 +49,21 @@ public class HockeyPlayer {
public String toString() {
String s =
String.format(
"Name: %s%nGoals: %d\tAssists: %d\tPoints: %d\tPoints Per Game: %d%nGames Won: %d\tGames Lost: %d\tGames"
+ " Played: %d%n",
name, goals, assists, getPoints(), getPointsPerGame(), gamesWon, gamesLost, getGamesPlayed());
"Name: %s%nGoals: %d\tAssists: %d\tPoints: %d\tPoints Per Game: %f%nGames Won: %d"
+ "\tGames Lost: %d\tGames Played: %d%n",
name,
goals,
assists,
getPoints(),
getPointsPerGame(),
gamesWon,
gamesLost,
getGamesPlayed());
return s;
}
public String getData() {
return String.format("%s %d %d %d %d", name, goals, assists, gamesWon, gamesLost);
return String.format("%s %d %d %d %d%n", name, goals, assists, gamesWon, gamesLost);
}
public boolean equals(Object o) {

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);
}
@@ -49,15 +51,17 @@ public class HockeyStats {
Select an option:
(1) Load Data from Files
(2) Open Data Editor
(3) Open Stats View Menu
(4) Quit
(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,18 +114,54 @@ 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;
}
try {
switch (k) {
case 1:
System.out.println(players.toString());
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:
saveData("save.txt");
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;
@@ -127,6 +170,9 @@ public class HockeyStats {
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;
}
@@ -134,14 +180,16 @@ public class HockeyStats {
System.out.print(
"""
<---------------------------->
Hockey Stats Viewer Menu
Hockey Stats Viewer
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
<---------------------------->
""");
@@ -149,24 +197,49 @@ 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;
}
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;
}
}

View File

@@ -1,6 +1,6 @@
<mxfile host="app.diagrams.net">
<diagram name="Page-1" id="zzZa4exWAZNGvPS8gC2z">
<mxGraphModel dx="1021" dy="531" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<mxGraphModel dx="1030" dy="535" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
@@ -41,12 +41,12 @@
<mxGeometry height="30" width="180" y="270" as="geometry" />
</mxCell>
<mxCell id="RQByykYFdltTPysqK5Cl-5" parent="1" style="swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;" value="PlayerList" vertex="1">
<mxGeometry height="370" width="250" x="340" y="620" as="geometry" />
<mxGeometry height="400" width="250" x="340" y="620" as="geometry" />
</mxCell>
<mxCell id="RQByykYFdltTPysqK5Cl-6" parent="RQByykYFdltTPysqK5Cl-5" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="- pList: ArrayList&amp;lt;HockeyPlayer&amp;gt;" vertex="1">
<mxGeometry height="30" width="250" y="30" as="geometry" />
</mxCell>
<mxCell id="RQByykYFdltTPysqK5Cl-8" parent="RQByykYFdltTPysqK5Cl-5" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="+ 2 4 13 addPlayer(Player): void" vertex="1">
<mxCell id="RQByykYFdltTPysqK5Cl-8" parent="RQByykYFdltTPysqK5Cl-5" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="+ 2 clear(): void" vertex="1">
<mxGeometry height="30" width="250" y="60" as="geometry" />
</mxCell>
<mxCell id="RQByykYFdltTPysqK5Cl-15" edge="1" parent="RQByykYFdltTPysqK5Cl-5" source="RQByykYFdltTPysqK5Cl-8" style="endArrow=none;html=1;rounded=0;entryX=1.01;entryY=0.987;entryDx=0;entryDy=0;entryPerimeter=0;exitX=0.006;exitY=0.013;exitDx=0;exitDy=0;exitPerimeter=0;" target="RQByykYFdltTPysqK5Cl-6" value="">
@@ -55,29 +55,32 @@
<mxPoint x="116" y="100" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="RQByykYFdltTPysqK5Cl-16" parent="RQByykYFdltTPysqK5Cl-5" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="+ 5 removePlayer(Player): boolean" vertex="1">
<mxCell id="dWSavgd9TV3ToYHsANoj-1" parent="RQByykYFdltTPysqK5Cl-5" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="+ 2 4 13 addPlayer(Player): void" vertex="1">
<mxGeometry height="30" width="250" y="90" as="geometry" />
</mxCell>
<mxCell id="RQByykYFdltTPysqK5Cl-17" parent="RQByykYFdltTPysqK5Cl-5" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="+ 6 toString(): String" vertex="1">
<mxCell id="RQByykYFdltTPysqK5Cl-16" parent="RQByykYFdltTPysqK5Cl-5" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="+ 5 removePlayer(Player): boolean" vertex="1">
<mxGeometry height="30" width="250" y="120" as="geometry" />
</mxCell>
<mxCell id="RQByykYFdltTPysqK5Cl-18" parent="RQByykYFdltTPysqK5Cl-5" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="+ 3 createSaveData(): String" vertex="1">
<mxCell id="RQByykYFdltTPysqK5Cl-17" parent="RQByykYFdltTPysqK5Cl-5" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="+ 6 toString(): String" vertex="1">
<mxGeometry height="30" width="250" y="150" as="geometry" />
</mxCell>
<mxCell id="RQByykYFdltTPysqK5Cl-28" parent="RQByykYFdltTPysqK5Cl-5" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="+ 7 13 findPlayer(String): HockeyPlayer" vertex="1">
<mxCell id="RQByykYFdltTPysqK5Cl-18" parent="RQByykYFdltTPysqK5Cl-5" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="+ 3 createSaveData(): String" vertex="1">
<mxGeometry height="30" width="250" y="180" as="geometry" />
</mxCell>
<mxCell id="RQByykYFdltTPysqK5Cl-29" parent="RQByykYFdltTPysqK5Cl-5" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="+ 8 sortByNames(): void" vertex="1">
<mxCell id="RQByykYFdltTPysqK5Cl-28" parent="RQByykYFdltTPysqK5Cl-5" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="+ 7 13 findPlayer(String): HockeyPlayer" vertex="1">
<mxGeometry height="30" width="250" y="210" as="geometry" />
</mxCell>
<mxCell id="RQByykYFdltTPysqK5Cl-29" parent="RQByykYFdltTPysqK5Cl-5" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="+ 8 sortByNames(): void" vertex="1">
<mxGeometry height="30" width="250" y="240" as="geometry" />
</mxCell>
<mxCell id="6J5Yf2fnFOG2eRTJ78eV-1" parent="RQByykYFdltTPysqK5Cl-5" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="+ 9 getPlayersGoalsAbove(int): PlayerList" vertex="1">
<mxGeometry height="50" width="250" y="240" as="geometry" />
<mxGeometry height="50" width="250" y="270" as="geometry" />
</mxCell>
<mxCell id="RQByykYFdltTPysqK5Cl-30" parent="RQByykYFdltTPysqK5Cl-5" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="+ 12 sortByPoints(): void" vertex="1">
<mxGeometry height="30" width="250" y="290" as="geometry" />
<mxGeometry height="30" width="250" y="320" as="geometry" />
</mxCell>
<mxCell id="EvRgQAmgYf5TB6QFYvy6-3" parent="RQByykYFdltTPysqK5Cl-5" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="+ 13 addGameToPlayer(String,int,int,boolean): HockeyPlayer" vertex="1">
<mxGeometry height="50" width="250" y="320" as="geometry" />
<mxGeometry height="50" width="250" y="350" as="geometry" />
</mxCell>
<mxCell id="RQByykYFdltTPysqK5Cl-9" parent="1" style="swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;" value="HockeyPlayer" vertex="1">
<mxGeometry height="650" width="190" x="344" y="1090" as="geometry" />

View File

@@ -7,11 +7,16 @@ public class PlayerList {
pList = new ArrayList<>();
}
public void clear() {
pList.clear();
}
public void addPlayer(HockeyPlayer p) {
pList.add(p);
}
public boolean removePlayer(HockeyPlayer p) {
public boolean removePlayer(String name) {
HockeyPlayer p = findPlayer(name);
return pList.remove(p);
}

View File

@@ -1,2 +0,0 @@
1
Connor McDavid 9 8 7 6

View File

@@ -1,2 +0,0 @@
1
Connor McDavid 9 8 7 6