diff options
| author | Willem Dalton <144246261+WillemDalton@users.noreply.github.com> | 2025-10-12 12:36:17 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-12 12:36:17 -0400 |
| commit | ab1c8dbf8e3fbd7ae1affd17e7b5596b1e58e839 (patch) | |
| tree | 91ed2c27e9735e05c8569f48e1130a95a7bdeb46 /src/main/java/design/controller/userinput/menus/CourseSearch.java | |
| parent | 1eca2f8681752ad359e8372780cdf719e2b1747d (diff) | |
| parent | 050118d5d029382ffc3b11e9f8159fb297007ef5 (diff) | |
| download | designproject-design-6-ab1c8dbf8e3fbd7ae1affd17e7b5596b1e58e839.tar.gz designproject-design-6-ab1c8dbf8e3fbd7ae1affd17e7b5596b1e58e839.tar.bz2 designproject-design-6-ab1c8dbf8e3fbd7ae1affd17e7b5596b1e58e839.zip | |
Merge pull request #12 from RIT-SWEN-262/menu-reorganize
Menu reorganize
Diffstat (limited to 'src/main/java/design/controller/userinput/menus/CourseSearch.java')
| -rw-r--r-- | src/main/java/design/controller/userinput/menus/CourseSearch.java | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/src/main/java/design/controller/userinput/menus/CourseSearch.java b/src/main/java/design/controller/userinput/menus/CourseSearch.java index 019965c..9d67b51 100644 --- a/src/main/java/design/controller/userinput/menus/CourseSearch.java +++ b/src/main/java/design/controller/userinput/menus/CourseSearch.java @@ -19,8 +19,9 @@ import java.util.Scanner; * The actual SEARCH feature of course searching. */ public class CourseSearch extends Menu { - CurrentSearchQuery query = CurrentSearchQuery.INSTANCE; - PersonalDatabase GolferDB = PersonalDatabase.INSTANCE; + private final CurrentSearchQuery query = CurrentSearchQuery.INSTANCE; + private final PersonalDatabase personalDB = PersonalDatabase.INSTANCE; + private final Golfer golfer = Session.getCurrentGolfer(); @Override public String getTitle() { @@ -28,22 +29,6 @@ public class CourseSearch extends Menu { } /* - * Prompt for input and search. - */ - public void search() { - System.out.print("Enter search term (blank for all): "); - Scanner sc = new Scanner(System.in); - String searchTerm = sc.nextLine(); - - // search and present - query.search(searchTerm); - this.present(); - - // reset the query after we're done. - query.reset(); - } - - /* * Display the results of our search. */ @Override @@ -64,6 +49,22 @@ public class CourseSearch extends Menu { return l; } + /* + * Prompt for input and search. + */ + @Override + public void present() { + System.out.print("Enter search term (blank for all): "); + Scanner sc = new Scanner(System.in); + String searchTerm = sc.nextLine(); + + // search and present + query.search(searchTerm); + super.present(); + + // reset the query after we're done. + query.reset(); + } // recursively go through tree structure of courselist to make menu options. // this is all for displaying the menu options, not the actual sorting. @@ -74,18 +75,10 @@ public class CourseSearch extends Menu { var name = String.format("%s, %s, Difficulty: %s, %s holes, %s total par", c.getName(), c.getLocation(), c.getDifficultyRating(), c.getHoleCount(), c.getTotalPar()); menuOptions.add(new MenuOption(name, () -> { - Golfer currentGolfer = Session.getCurrentGolfer(); - if (currentGolfer == null) { - // if we aren't logged in, notify the user. - System.out.println("\n\n !!! log into a golfer account to add courses to your profile. !!! \n\n"); - new MainMenu().present(); - return; - } - // add the course, try to save to DB. - currentGolfer.addCourse(c); + golfer.addCourse(c); try { - GolferDB.updateGolfer(currentGolfer); + personalDB.updateGolfer(golfer); } catch (IOException e) { e.printStackTrace(); // not sure if we should format this prettier for the user if the DB fails. } |
