everything basically

This commit is contained in:
CT
2026-04-25 02:15:25 -05:00
parent 27c3443f64
commit 1bd20c4af4
4 changed files with 177 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
public class HockeyPlayer {
String name;
int goals, assists, gamesWon, gamesLost;
public HockeyPlayer(String n, int g, int a, int gw, int gl) {
name = n;
goals = g;
assists = a;
gamesWon = gw;
gamesLost = gl;
}
public HockeyPlayer(String name) {
this.name = name;
}
public int getPoints() {
return goals + assists;
}
public int getGamesPlayed() {
return gamesWon + gamesLost;
}
public String toString() {
String s =
String.format(
"Name: %s%nGoals: %d%tAssists: %d%tPoints: %d%nGames Won: %d%tGames Lost: %d%tGames"
+ " Played: %d%n",
name, goals, assists, getPoints(), gamesWon, gamesLost, getGamesPlayed());
return s;
}
public boolean equals(Object o) {
HockeyPlayer p = (HockeyPlayer) o;
return this.name.equals(p.name);
}
public int compareTo(Object o) {
HockeyPlayer p = (HockeyPlayer) o;
return this.name.compareTo(p.name);
}
}

62
HockeyStats.java Normal file
View File

@@ -0,0 +1,62 @@
import java.io.*;
import java.util.*;
public class HockeyStats {
static PlayerList players = new PlayerList();
static BufferedReader br;
static StringTokenizer st;
public static void main(String[] args) throws Exception {
loadData("data.txt");
Scanner s = new Scanner(System.in);
while (true) {
showMenu();
int n = s.nextInt();
switch (n) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
default:
System.out.println("Please choose one of the available menu options!");
continue;
}
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());
}
public static void saveData(String fileName) throws Exception {
FileWriter fw = new FileWriter(fileName);
String s = players.createSaveData();
fw.write(s);
fw.close();
}
public static void showMenu() {
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
<---------------------------->
""");
}
}

72
PlayerList.java Normal file
View File

@@ -0,0 +1,72 @@
import java.util.ArrayList;
public class PlayerList {
ArrayList<HockeyPlayer> pList;
public PlayerList() {
pList = new ArrayList<>();
}
public void addPlayer(HockeyPlayer p) {
pList.add(p);
}
public boolean removePlayer(HockeyPlayer p) {
return pList.remove(p);
}
public String toString() {
String s = "";
for (HockeyPlayer p : pList) {
s += p.toString();
}
return s;
}
public String createSaveData() {
String s = pList.size() + "\n";
for (HockeyPlayer p : pList) {
s += p.name + p.goals + p.assists + p.gamesWon + p.gamesLost + "\n";
}
return s;
}
public HockeyPlayer findPlayer(String name) {
HockeyPlayer newPlayer = new HockeyPlayer(name);
for (HockeyPlayer p : pList) {
if (p.equals(newPlayer)) return p;
}
return null;
}
public void sortByNames() {
for (int i = 0; i < pList.size(); i++) {
boolean swapped = false;
for (int j = 0; j < pList.size() - 1 - i; j++) {
if (pList.get(j).compareTo(pList.get(j + 1)) > 0) {
HockeyPlayer temp = pList.get(j);
pList.set(j, pList.get(j + 1));
pList.set(j + 1, temp);
swapped = true;
}
}
if (!swapped) break;
}
}
// if (pList.get(i).getPoints() > pList.get(j).getPoints()) {
public void sortByPoints() {
for (int i = 0; i < pList.size(); i++) {
int minInd = i;
for (int j = i + 1; j < pList.size(); j++) {
if (pList.get(minInd).getPoints() > pList.get(j).getPoints()) {
minInd = j;
}
}
HockeyPlayer temp = pList.get(minInd);
pList.set(minInd, pList.get(i));
pList.set(i, temp);
}
}
}