package design.controller.userinput.menus; import design.controller.userinput.Menu; import design.controller.userinput.MenuOption; import design.model.course_search.CurrentSearchQuery; import design.model.course_search.ICourse; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class SelectCourse extends Menu { CurrentSearchQuery query = CurrentSearchQuery.INSTANCE; @Override public String getTitle() { return "select course"; } /* * 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(); query.search(searchTerm); present(); } /* * Display the results of our search. */ @Override public List getMenuOptions() { var l = new ArrayList(); List queryResult = query.getQueryResult().getCourses(); // we always want to return to menu as an option. l.add(new MenuOption("return to main menu", (a) -> new MainMenu().present())); // no results? let the user know. if (queryResult.isEmpty()) { System.out.println("\nNo matching courses found.\n"); } // add all of our results. l.addAll(query.getQueryResult().getCourses().stream() .map(i -> new MenuOption( i.getName() + ", " + i.getLocation() + ", Difficulty: " + i.getDifficultyRating() + ", " + i.getHoleCount() + " holes", (a) -> {})).toList()); // TO DO: inputing the # for the course should add it to the user's profile return l; } }