diff options
| author | Jacob Shimp <jrs9538@g.rit.edu> | 2025-10-08 21:48:53 -0400 |
|---|---|---|
| committer | Jacob Shimp <jrs9538@g.rit.edu> | 2025-10-08 21:48:53 -0400 |
| commit | 871f353b9d8765594983b8b85d541f0c27447f68 (patch) | |
| tree | 82c3d06fb8e21fe1bb6a29ac3ba51106c1d900c3 /src/main/java/design/controller/userinput | |
| parent | 4a720e851d188688571e2f5c7f46b6389e9a429f (diff) | |
| download | designproject-design-6-871f353b9d8765594983b8b85d541f0c27447f68.tar.gz designproject-design-6-871f353b9d8765594983b8b85d541f0c27447f68.tar.bz2 designproject-design-6-871f353b9d8765594983b8b85d541f0c27447f68.zip | |
implemented all other menu options
Diffstat (limited to '')
| -rw-r--r-- | src/main/java/design/controller/userinput/menus/StatisticsMenu.java | 64 |
1 files changed, 44 insertions, 20 deletions
diff --git a/src/main/java/design/controller/userinput/menus/StatisticsMenu.java b/src/main/java/design/controller/userinput/menus/StatisticsMenu.java index 16d875a..669d270 100644 --- a/src/main/java/design/controller/userinput/menus/StatisticsMenu.java +++ b/src/main/java/design/controller/userinput/menus/StatisticsMenu.java @@ -4,8 +4,13 @@ import design.controller.userinput.Menu; import design.controller.userinput.MenuOption; import design.model.Course; import design.model.Golfer; +import design.model.Hole; +import design.model.Play; +import design.model.Round; import design.model.statistics.CourseStats; +import design.model.statistics.HoleStats; import design.model.statistics.LifetimeStats; +import design.model.statistics.RoundStats; import design.model.statistics.Statistics; import design.model.statistics.YearlyStats; import design.runtime.Session; @@ -22,6 +27,7 @@ public class StatisticsMenu extends Menu { return "statistics menu"; } + @SuppressWarnings("resource") private Statistics getUserYear(Statistics baseStats){ Scanner sc = new Scanner(System.in); @@ -32,33 +38,48 @@ public class StatisticsMenu extends Menu { return yearStats; } + @SuppressWarnings("resource") 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; - } + 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()); } - return null; + 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){ - return null; + 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 baseStatistics){ - return null; + @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 @@ -67,6 +88,7 @@ public class StatisticsMenu extends Menu { 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(); @@ -96,6 +118,7 @@ public class StatisticsMenu extends Menu { 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); @@ -106,7 +129,8 @@ public class StatisticsMenu extends Menu { System.out.printf("Total swings: %d\n", holeStats.get_score()); System.out.printf("Total distance: %.1f\n", holeStats.get_distance()); + this.present(); }) ); } -} +}
\ No newline at end of file |
