Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>23</maven.compiler.source>
<maven.compiler.target>23</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
165 changes: 165 additions & 0 deletions src/main/java/object/jordaneldridge/BasketballPlayerStats.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package object.jordaneldridge;
import java.util.ArrayList;
import java.util.List;



public class BasketballPlayerStats {

private int playerId;
private String firstName;
private String lastName;
private String team;
private int points;
private int rebounds;
private int assists;



public BasketballPlayerStats(int playerId,
String firstName,
String lastName,
String team,
int points,
int rebounds,
int assists) {

if (points < 0 || rebounds < 0 || assists < 0) {
throw new IllegalArgumentException("Points, rebounds, and assists cannot be negative.");
}

this.playerId = playerId;
this.firstName = firstName;
this.lastName = lastName;
this.team = team;
this.points = points;
this.rebounds = rebounds;
this.assists = assists;
}

private List<GameStat> games = new ArrayList<>();


// Getters
public int getPlayerId() {
return playerId;
}

public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}

public String getTeam() {
return team;
}

public int getPoints() {
return points;
}

public int getRebounds() {
return rebounds;
}

public int getAssists() {
return assists;
}

// Setters
public void setPlayerId(int playerId) {
this.playerId = playerId;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public void setTeam(String team) {
this.team = team;
}

public void setPoints(int points) {
if (points < 0) {
throw new IllegalArgumentException("Points cannot be negative.");
}
this.points = points;
}

public void setRebounds(int rebounds) {
if (rebounds < 0) {
throw new IllegalArgumentException("Rebounds cannot be negative.");
}
this.rebounds = rebounds;
}

public void setAssists(int assists) {
if (assists < 0) {
throw new IllegalArgumentException("Assists cannot be negative.");
}
this.assists = assists;
}

public void recordGame(int pts, int reb, int ast) {

if (pts < 0 || reb < 0 || ast < 0) {
throw new IllegalArgumentException("Game stats cannot be negative.");
}

GameStat game = new GameStat(pts, reb, ast);
games.add(game);

this.points += pts;
this.rebounds += reb;
this.assists += ast;
}

public double calculatePointsPerGame() {

if (games.isEmpty()) {
throw new IllegalStateException("No games recorded.");
}

return (double) points / games.size();
}

public String getGameBreakdown() {

if (games.isEmpty()) {
return "No games recorded.";
}

StringBuilder breakdown = new StringBuilder();

for (int i = 0; i < games.size(); i++) {
GameStat game = games.get(i);

breakdown.append("Game ")
.append(i + 1)
.append(": ")
.append(game.getPoints())
.append(" PTS, ")
.append(game.getRebounds())
.append(" REB, ")
.append(game.getAssists())
.append(" AST\n");
}

return breakdown.toString();
}




public String getSummary() {
return String.format("%s %s (%s): %d PTS, %d REB, %d AST",
firstName, lastName, team, points, rebounds, assists);
}
}
30 changes: 30 additions & 0 deletions src/main/java/object/jordaneldridge/GameStat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package object.jordaneldridge;

public class GameStat {

private int points;
private int rebounds;
private int assists;

public GameStat(int points, int rebounds, int assists) {
if (points < 0 || rebounds < 0 || assists < 0) {
throw new IllegalArgumentException("Stats cannot be negative.");
}

this.points = points;
this.rebounds = rebounds;
this.assists = assists;
}

public int getPoints() {
return points;
}

public int getRebounds() {
return rebounds;
}

public int getAssists() {
return assists;
}
}
Loading