blob: 0195bcfa8e0c54dc832ba82e240b8c7c091743d6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
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<MenuOption> getMenuOptions()
{
var l = new ArrayList<MenuOption>();
List<ICourse> 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;
}
}
|