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 {
private String name;
private 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 String getName() {
return name;
}
public int getGoals() {
return goals;
}
public int getAssists() {
return assists;
}
public int getGamesWon() {
return gamesWon;
}
public int getGamesLost() {
return gamesLost;
}
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 String getData() {
return String.format("%s %d %d %d %d", name, goals, assists, gamesWon, gamesLost);
}
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);
}
}
public class HockeyPlayer {
private String name;
private 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 String getName() {
return name;
}
public int getGoals() {
return goals;
}
public int getAssists() {
return assists;
}
public int getGamesWon() {
return gamesWon;
}
public int getGamesLost() {
return gamesLost;
}
public int getPoints() {
return goals + assists;
}
public int getGamesPlayed() {
return gamesWon + gamesLost;
}
public double getPointsPerGame(){
return (double) getPoints() / (double) getGamesPlayed();
}
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());
return s;
}
public String getData() {
return String.format("%s %d %d %d %d", name, goals, assists, gamesWon, gamesLost);
}
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);
}
}