diff options
| author | Tyler Ferrari <69283684+Sowgro@users.noreply.github.com> | 2025-10-07 09:08:33 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-07 09:08:33 -0400 |
| commit | a119e407dbc13cdd28009ae5acea67f9311e0e9b (patch) | |
| tree | 69400f475e5253ecba923d8201e07537c8de7e56 | |
| parent | ff2e4efb6e4a2089caaf494438bd2b86bd05ae61 (diff) | |
| parent | 8ce871d5ed3a694f75478f0078e29af6030f93f8 (diff) | |
| download | designproject-design-6-a119e407dbc13cdd28009ae5acea67f9311e0e9b.tar.gz designproject-design-6-a119e407dbc13cdd28009ae5acea67f9311e0e9b.tar.bz2 designproject-design-6-a119e407dbc13cdd28009ae5acea67f9311e0e9b.zip | |
Merge pull request #7 from RIT-SWEN-262/lizzio-CourseSelectMenu
Lizzio course select menu
| -rw-r--r-- | data/personaldb.json | 71 | ||||
| -rw-r--r-- | src/main/java/design/controller/userinput/menus/CourseSelectMenu.java | 76 |
2 files changed, 131 insertions, 16 deletions
diff --git a/data/personaldb.json b/data/personaldb.json index 5ba73ac..75faec5 100644 --- a/data/personaldb.json +++ b/data/personaldb.json @@ -3,8 +3,75 @@ "username": "john_doe", "passwordHash": 12345, "fullName": "John Doe", - "courses": [], - "rounds": [], + "courses": [ + 1, + 2 + ], + "rounds": [ + { + "course": 2, + "dateTime": [ + 2025, + 10, + 7, + 9, + 4, + 6, + 798620300 + ], + "startingHole": { + "number": 3, + "par": 5 + }, + "plays": [ + { + "holeNumber": 3, + "swings": [ + { + "distance": 1000, + "clubUsed": { + "manufacture": "Generic", + "nickname": "Tyler", + "clubType": "DRIVER" + } + }, + { + "distance": 250, + "clubUsed": { + "manufacture": "Generic", + "nickname": "Tyler", + "clubType": "DRIVER" + } + } + ], + "distance": 1250, + "swingCount": 2 + }, + { + "holeNumber": 4, + "swings": [ + { + "distance": 125, + "clubUsed": { + "manufacture": "Generic", + "nickname": "Dman", + "clubType": "DRIVER" + } + } + ], + "distance": 125, + "swingCount": 1 + } + ], + "currentHoleIndex": 4, + "totalDistance": 1375.0, + "currentHole": { + "number": 5, + "par": 3 + }, + "totalSwings": 3 + } + ], "clubs": [ { "manufacture": "TaylorMade", diff --git a/src/main/java/design/controller/userinput/menus/CourseSelectMenu.java b/src/main/java/design/controller/userinput/menus/CourseSelectMenu.java index 8df9823..af825e0 100644 --- a/src/main/java/design/controller/userinput/menus/CourseSelectMenu.java +++ b/src/main/java/design/controller/userinput/menus/CourseSelectMenu.java @@ -28,25 +28,73 @@ public class CourseSelectMenu extends Menu { // 0) back opts.add(new MenuOption("back to main menu", () -> new MainMenu().present())); - // 1) pick course by number TODO: add error checking - opts.add(new MenuOption("pick course by number (1..1000)", () -> { - Scanner sc = new Scanner(System.in); - - System.out.print("Course number (1..1000): "); - int n = Integer.parseInt(sc.nextLine().trim()); - Course c = MasterDatabase.INSTANCE.getCourse(n - 1); + // 1) go to CourseSearchMenu to search for a course and add it profile + opts.add(new MenuOption("Add Course to Profile", () -> new MainMenu().present())); - System.out.print("Starting hole (1..18, blank=1): "); - String s = sc.nextLine().trim(); - int start = s.isEmpty() ? 1 : Integer.parseInt(s); + // 2) pick course from MY PROFILE only + opts.add(new MenuOption("pick course from my profile", () -> { + var golfer = Session.getCurrentGolfer(); + Course[] mine = (golfer == null) ? new Course[0] : golfer.getCourses(); - Hole startHole = c.getHoles().get(start - 1); + // Checks user has courses of not informs them to add one to there profile + if (mine == null || mine.length == 0) { + System.out.println("You don't have any courses saved to your profile yet."); + System.out.println("Use the 'Add Course to Profile' menu first."); + this.present(); + return; + } + // Select a course + Scanner sc = new Scanner(System.in); - Round r = new Round(c, LocalDateTime.now(), startHole); - Session.getCurrentGolfer().addRound(r); - new HolePlayMenu(r).present(); + // Prints all courses + System.out.println("-- MY COURSES --"); + for (int i = 0; i < mine.length; i++) { + Course c = mine[i]; + System.out.printf("%d: %s (%s) | Holes: %d | Total Par: %d | Difficulty: %.1f%n", + i + 1, c.getName(), c.getLocation(), c.getHoleCount(), c.getTotalPar(), + c.getDifficultyRating()); + } + // Select course by number + Course selected = null; + while (selected == null) { + System.out.print("Select course # (1.." + mine.length + "): "); + String line = sc.nextLine().trim(); + int idx = Integer.parseInt(line); + if (idx < 1 || idx > mine.length) { + System.out.println("Out of range. Try again."); + continue; + } + selected = mine[idx - 1]; + } + // Gets starting hole on course + int startHoleNum = readStartingHole(sc, selected.getHoleCount()); + // Starts round and sends user to HolePlayMenu + startRound(selected, startHoleNum); })); return opts; } + + private int readStartingHole(Scanner sc, int holeCount) { + // Asks for a hole number until a valid number is selected + while (true) { + System.out.print("Starting hole (1.." + holeCount + ", blank=1): "); + String s = sc.nextLine().trim(); + if (s.isEmpty()) + return 1; + int start = Integer.parseInt(s); + if (start < 1 || start > holeCount) { + System.out.println("Starting hole must be between 1 and " + holeCount + "."); + continue; + } + return start; + } + } + + private void startRound(Course c, int startHoleNum) { + Hole startHole = c.getHoles().get(startHoleNum - 1); + Round r = new Round(c, LocalDateTime.now(), startHole); + Session.getCurrentGolfer().addRound(r); + new HolePlayMenu(r).present(); + } } |
