diff options
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. } |
