This commit is contained in:
CT
2026-04-30 19:59:29 +00:00
parent beb96d4a97
commit 15ffe12fbf

View File

@@ -1,67 +1,71 @@
public class HockeyPlayer { public class HockeyPlayer {
private String name; private String name;
private int goals, assists, gamesWon, gamesLost; private int goals, assists, gamesWon, gamesLost;
public HockeyPlayer(String n, int g, int a, int gw, int gl) { public HockeyPlayer(String n, int g, int a, int gw, int gl) {
name = n; name = n;
goals = g; goals = g;
assists = a; assists = a;
gamesWon = gw; gamesWon = gw;
gamesLost = gl; gamesLost = gl;
} }
public HockeyPlayer(String name) { public HockeyPlayer(String name) {
this.name = name; this.name = name;
} }
public String getName() { public String getName() {
return name; return name;
} }
public int getGoals() { public int getGoals() {
return goals; return goals;
} }
public int getAssists() { public int getAssists() {
return assists; return assists;
} }
public int getGamesWon() { public int getGamesWon() {
return gamesWon; return gamesWon;
} }
public int getGamesLost() { public int getGamesLost() {
return gamesLost; return gamesLost;
} }
public int getPoints() { public int getPoints() {
return goals + assists; return goals + assists;
} }
public int getGamesPlayed() { public int getGamesPlayed() {
return gamesWon + gamesLost; return gamesWon + gamesLost;
} }
public String toString() { public double getPointsPerGame(){
String s = return (double) getPoints() / (double) getGamesPlayed();
String.format( }
"Name: %s%nGoals: %d\tAssists: %d\tPoints: %d%nGames Won: %d\tGames Lost: %d\tGames"
+ " Played: %d%n", public String toString() {
name, goals, assists, getPoints(), gamesWon, gamesLost, getGamesPlayed()); String s =
return 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",
public String getData() { name, goals, assists, getPoints(), getPointsPerGame(), gamesWon, gamesLost, getGamesPlayed());
return String.format("%s %d %d %d %d", name, goals, assists, gamesWon, gamesLost); return s;
} }
public boolean equals(Object o) { public String getData() {
HockeyPlayer p = (HockeyPlayer) o; return String.format("%s %d %d %d %d", name, goals, assists, gamesWon, gamesLost);
return this.name.equals(p.name); }
}
public boolean equals(Object o) {
public int compareTo(Object o) { HockeyPlayer p = (HockeyPlayer) o;
HockeyPlayer p = (HockeyPlayer) o; return this.name.equals(p.name);
return this.name.compareTo(p.name); }
}
} public int compareTo(Object o) {
HockeyPlayer p = (HockeyPlayer) o;
return this.name.compareTo(p.name);
}
}