From b50bce5a1c303e03cc50e1945de9c16cee044976 Mon Sep 17 00:00:00 2001 From: Michael Lizzio Date: Tue, 7 Oct 2025 13:14:41 -0400 Subject: Added AddClubMenu and modified club and golfer to allow club id's, added menu to UserSettings --- src/main/java/design/model/Club.java | 13 ++++++++++++- src/main/java/design/model/Golfer.java | 19 +++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'src/main/java/design/model') diff --git a/src/main/java/design/model/Club.java b/src/main/java/design/model/Club.java index 57a43d1..9fa3c87 100644 --- a/src/main/java/design/model/Club.java +++ b/src/main/java/design/model/Club.java @@ -13,16 +13,22 @@ public class Club { PUTTER } + private final int id; private final String manufacture; private final String nickname; private final ClubType clubType; - public Club(String manufacture, String nickname, ClubType clubType) { + public Club(int id, String manufacture, String nickname, ClubType clubType) { + this.id = id; this.manufacture = manufacture; this.nickname = nickname; this.clubType = clubType; } + public int getId() { + return id; + } + public String getManufacture() { return manufacture; } @@ -34,4 +40,9 @@ public class Club { public ClubType getClubType() { return clubType; } + + @Override + public String toString() { + return String.format("#%d %s - %s (%s)", id, nickname, manufacture, clubType); + } } diff --git a/src/main/java/design/model/Golfer.java b/src/main/java/design/model/Golfer.java index 19d6ac6..d34073f 100644 --- a/src/main/java/design/model/Golfer.java +++ b/src/main/java/design/model/Golfer.java @@ -11,15 +11,19 @@ public class Golfer { private String fullName; private final List courses; private final List rounds; - private final List clubs = new ArrayList<>(); // Keep track of golfer's clubs + private final List clubs; // Keep track of golfer's clubs + private int nextClubId = 1; @JsonCreator - private Golfer(String username, int passwordHash, String fullName, List courses, List rounds) { + private Golfer(String username, int passwordHash, String fullName, List courses, List rounds, + List clubs) { this.username = username; this.passwordHash = passwordHash; this.fullName = fullName; this.courses = courses; this.rounds = rounds; + this.clubs = clubs; + this.nextClubId = this.clubs.stream().mapToInt(Club::getId).max().orElse(0) + 1; } public Golfer(String fullName, String username, String password) { @@ -28,6 +32,8 @@ public class Golfer { this.passwordHash = password.hashCode(); this.courses = new ArrayList<>(); this.rounds = new ArrayList<>(); + this.clubs = new ArrayList<>(); + this.nextClubId = 1; } public String getUsername() { @@ -74,12 +80,17 @@ public class Golfer { rounds.add(round); } - // Helpers dealing with clubs - public void addClub(Club c) { + public Club addClub(String manufacture, String nickname, Club.ClubType type) { + Club c = new Club(nextClubId++, manufacture, nickname, type); clubs.add(c); + return c; } public boolean hasClub(Club c) { return clubs.contains(c); } + + public Club[] getClubs() { + return clubs.toArray(Club[]::new); + } } -- cgit v1.2.3