From 5f1ea0ee335a73edf53939b87218a34e93fe4de9 Mon Sep 17 00:00:00 2001 From: sowgro Date: Thu, 9 Oct 2025 21:03:25 -0400 Subject: Menu cleanup - pass 1 --- .../controller/userinput/menus/StatisticsMenu.java | 108 ++++++++++----------- 1 file changed, 52 insertions(+), 56 deletions(-) (limited to 'src/main/java/design/controller/userinput/menus/StatisticsMenu.java') diff --git a/src/main/java/design/controller/userinput/menus/StatisticsMenu.java b/src/main/java/design/controller/userinput/menus/StatisticsMenu.java index 3af790e..8835ce1 100644 --- a/src/main/java/design/controller/userinput/menus/StatisticsMenu.java +++ b/src/main/java/design/controller/userinput/menus/StatisticsMenu.java @@ -27,62 +27,6 @@ public class StatisticsMenu extends Menu { return "statistics menu"; } - // Helper classes to get user input and handle finding the data they requested (Course, Hole, Year, etc.) - @SuppressWarnings("resource") - 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; - } - - @SuppressWarnings("resource") - private Statistics getUserCourse(Statistics baseStats){ - Scanner sc = new Scanner(System.in); - Course[] courses = golfer.getCourses(); - for(int i = 0; i < courses.length; i++){ - System.out.println((i+1) + ".) Name: " + courses[i].getName() + ". Location: " + courses[i].getLocation()); - } - System.out.println("Select the course number corresponding to the course. "); - int selection = Integer.parseInt(sc.nextLine()); - return new CourseStats(baseStats, courses[selection - 1]); - } - - @SuppressWarnings("resource") - private Statistics getUserRound(Statistics baseStats){ - Scanner sc = new Scanner(System.in); - Round[] rounds = baseStats.getRounds(); - for(int i = 0; i < rounds.length; i++){ - System.out.println((i+1) + ".) Date: " + rounds[i].getDateTime().toLocalDate() + ". Time: " + rounds[i].getDateTime().toLocalTime() + ". Final Score: " + rounds[i].getTotalSwings() + ". Total Distance: " + rounds[i].getTotalDistance()); - } - System.out.println("Select the round number: "); - int selection = Integer.parseInt(sc.nextLine()); - return new RoundStats(baseStats, rounds[selection - 1]); - } - - @SuppressWarnings("resource") - private Statistics getUserHole(Statistics baseStats){ - Scanner sc = new Scanner(System.in); - Round round = baseStats.getRounds()[0]; // Only 1 round - Play[] plays = round.getPlays(); - for(Play play : plays){ - System.out.println("Hole number: " + play.getHoleNumber()); - } - System.out.println("Enter the hole number: "); - int holeNum = Integer.parseInt(sc.nextLine()); - - Course course = round.getCourse(); - for(Hole hole : course.getHoles()){ - if(hole.getNumber() == holeNum){ - return new HoleStats(baseStats, hole); - } - } - return baseStats; - } - @Override public List getMenuOptions() { return List.of( @@ -134,4 +78,56 @@ public class StatisticsMenu extends Menu { }) ); } + + // Helper classes to get user input and handle finding the data they requested (Course, Hole, Year, etc.) + 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); + Course[] courses = golfer.getCourses(); + for(int i = 0; i < courses.length; i++){ + System.out.println((i+1) + ".) Name: " + courses[i].getName() + ". Location: " + courses[i].getLocation()); + } + System.out.println("Select the course number corresponding to the course. "); + int selection = Integer.parseInt(sc.nextLine()); + return new CourseStats(baseStats, courses[selection - 1]); + } + + private Statistics getUserRound(Statistics baseStats){ + Scanner sc = new Scanner(System.in); + Round[] rounds = baseStats.getRounds(); + for(int i = 0; i < rounds.length; i++){ + System.out.println((i+1) + ".) Date: " + rounds[i].getDateTime().toLocalDate() + ". Time: " + rounds[i].getDateTime().toLocalTime() + ". Final Score: " + rounds[i].getTotalSwings() + ". Total Distance: " + rounds[i].getTotalDistance()); + } + System.out.println("Select the round number: "); + int selection = Integer.parseInt(sc.nextLine()); + return new RoundStats(baseStats, rounds[selection - 1]); + } + + private Statistics getUserHole(Statistics baseStats){ + Scanner sc = new Scanner(System.in); + Round round = baseStats.getRounds()[0]; // Only 1 round + Play[] plays = round.getPlays(); + for(Play play : plays){ + System.out.println("Hole number: " + play.getHoleNumber()); + } + System.out.println("Enter the hole number: "); + int holeNum = Integer.parseInt(sc.nextLine()); + + Course course = round.getCourse(); + for(Hole hole : course.getHoles()){ + if(hole.getNumber() == holeNum){ + return new HoleStats(baseStats, hole); + } + } + return baseStats; + } } \ No newline at end of file -- cgit v1.2.3 From fac7fb71260b901a893b5b90aae23e86d6c23550 Mon Sep 17 00:00:00 2001 From: sowgro Date: Sat, 11 Oct 2025 22:24:54 -0400 Subject: Menu cleanup - pass 2 --- .../controller/userinput/menus/StatisticsMenu.java | 109 +++++++++++---------- 1 file changed, 57 insertions(+), 52 deletions(-) (limited to 'src/main/java/design/controller/userinput/menus/StatisticsMenu.java') diff --git a/src/main/java/design/controller/userinput/menus/StatisticsMenu.java b/src/main/java/design/controller/userinput/menus/StatisticsMenu.java index 8835ce1..9ce0bd0 100644 --- a/src/main/java/design/controller/userinput/menus/StatisticsMenu.java +++ b/src/main/java/design/controller/userinput/menus/StatisticsMenu.java @@ -19,8 +19,7 @@ import java.util.List; import java.util.Scanner; public class StatisticsMenu extends Menu { - - Golfer golfer = Session.getCurrentGolfer(); + private final Golfer golfer = Session.getCurrentGolfer(); @Override public String getTitle() { @@ -29,54 +28,61 @@ public class StatisticsMenu extends Menu { @Override public List getMenuOptions() { - return List.of( - new MenuOption("return to main menu", () -> new MainMenu().present()), - 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); - Statistics yearStats = getUserYear(baseStats); - Statistics courseStats = getUserCourse(yearStats); - Statistics roundStats = getUserRound(courseStats); - - System.out.printf("Total swings: %d\n", roundStats.get_score()); - System.out.printf("Total distance: %.1f\n", roundStats.get_distance()); - this.present(); - }), - new MenuOption("view hole statistics", () -> { - Statistics baseStats = new LifetimeStats(golfer); - Statistics yearStats = getUserYear(baseStats); - Statistics courseStats = getUserCourse(yearStats); - Statistics roundStats = getUserRound(courseStats); - Statistics holeStats = getUserHole(roundStats); - - System.out.printf("Total swings: %d\n", holeStats.get_score()); - System.out.printf("Total distance: %.1f\n", holeStats.get_distance()); - this.present(); - }) - ); + List opts = new java.util.ArrayList<>(); + + opts.add(new MenuOption("return to main menu", () -> new MainMenu().present())); + + opts.add(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(); + })); + + opts.add(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(); + })); + + opts.add(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(); + })); + + opts.add(new MenuOption("view round statistics", () -> { + Statistics baseStats = new LifetimeStats(golfer); + Statistics yearStats = getUserYear(baseStats); + Statistics courseStats = getUserCourse(yearStats); + Statistics roundStats = getUserRound(courseStats); + + System.out.printf("Total swings: %d\n", roundStats.get_score()); + System.out.printf("Total distance: %.1f\n", roundStats.get_distance()); + this.present(); + })); + + opts.add(new MenuOption("view hole statistics", () -> { + Statistics baseStats = new LifetimeStats(golfer); + Statistics yearStats = getUserYear(baseStats); + Statistics courseStats = getUserCourse(yearStats); + Statistics roundStats = getUserRound(courseStats); + Statistics holeStats = getUserHole(roundStats); + + System.out.printf("Total swings: %d\n", holeStats.get_score()); + System.out.printf("Total distance: %.1f\n", holeStats.get_distance()); + this.present(); + })); + + return opts; } // Helper classes to get user input and handle finding the data they requested (Course, Hole, Year, etc.) @@ -86,8 +92,7 @@ public class StatisticsMenu extends Menu { System.out.println("Enter year to search: "); int year = Integer.parseInt(sc.nextLine()); - Statistics yearStats = new YearlyStats(baseStats, year); - return yearStats; + return new YearlyStats(baseStats, year); } private Statistics getUserCourse(Statistics baseStats){ -- cgit v1.2.3