diff options
Diffstat (limited to '')
| -rw-r--r-- | data/personaldb.json | 71 | ||||
| -rw-r--r-- | src/main/java/design/controller/userinput/menus/StatisticsMenu.java | 86 |
2 files changed, 153 insertions, 4 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/StatisticsMenu.java b/src/main/java/design/controller/userinput/menus/StatisticsMenu.java index ebd2e3f..c299d3e 100644 --- a/src/main/java/design/controller/userinput/menus/StatisticsMenu.java +++ b/src/main/java/design/controller/userinput/menus/StatisticsMenu.java @@ -2,29 +2,111 @@ package design.controller.userinput.menus; import design.controller.userinput.Menu; import design.controller.userinput.MenuOption; +import design.model.Course; import design.model.Golfer; +import design.model.statistics.CourseStats; import design.model.statistics.LifetimeStats; import design.model.statistics.Statistics; +import design.model.statistics.YearlyStats; import design.runtime.Session; import java.util.List; +import java.util.Scanner; public class StatisticsMenu extends Menu { + Golfer golfer = Session.getCurrentGolfer(); + @Override public String getTitle() { return "statistics menu"; } + private Statistics getUserYear(Statistics baseStats){ + Scanner sc = new Scanner(System.in); + + System.out.println("Enter year to search: "); + int year = Integer.parseInt(sc.nextLine()); + + Statistics yearStats = new YearlyStats(baseStats, year); + return yearStats; + } + + private Statistics getUserCourse(Statistics baseStats){ + Scanner sc = new Scanner(System.in); + + System.out.println("Enter course name to search: "); + String courseName = sc.nextLine(); + System.out.println("Enter location of course"); + String courseLocation = sc.nextLine(); + + Course course = matchCourse(courseName, courseLocation); + Statistics courseStats = new CourseStats(baseStats, course); + return courseStats; + } + private Course matchCourse(String courseName, String courseLocation){ + for(Course course : golfer.getCourses()){ + if(course.getName().toLowerCase().equals(courseName.toLowerCase()) && course.getLocation().toLowerCase().equals(courseLocation.toLowerCase())){ + return course; + } + } + return null; + } + + private Statistics getUserRound(Statistics baseStats){ + return null; + } + @Override public List<MenuOption> getMenuOptions() { return List.of( new MenuOption("return to main menu", () -> new MainMenu().present()), - new MenuOption("view lifetime stats", () -> { - Golfer golfer = Session.getCurrentGolfer(); + new MenuOption("view lifetime statistics", () -> { Statistics stats = new LifetimeStats(golfer); System.out.printf("Total swings: %d\n", stats.get_score()); System.out.printf("Total distance: %.1f\n", stats.get_distance()); + this.present(); + }), + new MenuOption("view yearly statistics", () -> { + Statistics baseStats = new LifetimeStats(golfer); + Statistics yearStats = getUserYear(baseStats); + + System.out.printf("Total swings: %d\n", yearStats.get_score()); + System.out.printf("Total distance: %.1f\n", yearStats.get_distance()); + this.present(); + }), + new MenuOption("view course statistics", () -> { + Statistics baseStats = new LifetimeStats(golfer); + Statistics yearStats = getUserYear(baseStats); + Statistics courseStats = getUserCourse(yearStats); + + System.out.printf("Total swings: %d\n", courseStats.get_score()); + System.out.printf("Total distance: %.1f\n", courseStats.get_distance()); + this.present(); + }), + new MenuOption("view round statistics", () -> { + Statistics baseStats = new LifetimeStats(golfer); + Scanner sc = new Scanner(System.in); + + System.out.println("Enter year to search: "); + int year = sc.nextInt(); + Statistics yearStats = new YearlyStats(baseStats, year); + + System.out.printf("Total swings: %d\n", yearStats.get_score()); + System.out.printf("Total distance: %.1f\n", yearStats.get_distance()); + sc.close(); + }), + new MenuOption("view hole statistics", () -> { + Statistics baseStats = new LifetimeStats(golfer); + Scanner sc = new Scanner(System.in); + + System.out.println("Enter year to search: "); + int year = sc.nextInt(); + Statistics yearStats = new YearlyStats(baseStats, year); + + System.out.printf("Total swings: %d\n", yearStats.get_score()); + System.out.printf("Total distance: %.1f\n", yearStats.get_distance()); + sc.close(); }) ); } |
