summaryrefslogtreecommitdiff
path: root/src/main/java/design/controller/userinput/menus/StatisticsMenu.java
blob: 16d875ade9582adff1d3d7d064a133a3bd00d03f (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package design.controller.userinput.menus;

import design.controller.userinput.Menu;
import design.controller.userinput.MenuOption;
import design.model.Course;
import design.model.Golfer;
import design.model.statistics.CourseStats;
import design.model.statistics.LifetimeStats;
import design.model.statistics.Statistics;
import design.model.statistics.YearlyStats;
import design.runtime.Session;

import java.util.List;
import java.util.Scanner;

public class StatisticsMenu extends Menu {

    Golfer golfer = Session.getCurrentGolfer();
    
    @Override
    public String getTitle() {
        return "statistics menu";
    }

    private Statistics getUserYear(Statistics baseStats){
        Scanner sc = new Scanner(System.in);

        System.out.println("Enter year to search: ");
        int year = Integer.parseInt(sc.nextLine());

        Statistics yearStats = new YearlyStats(baseStats, year);
        return yearStats;
    }

    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;
            }
        }
        return null;
    }

    private Statistics getUserRound(Statistics baseStats){
        return null;
    }

    private Statistics getUserHole(Statistics baseStatistics){
        return null;
    }

    @Override
    public List<MenuOption> getMenuOptions() {
        return List.of(
                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();
                }),
                new MenuOption("view yearly statistics", () -> {
                    Statistics baseStats = new LifetimeStats(golfer);
                    Statistics yearStats = getUserYear(baseStats);

                    System.out.printf("Total swings: %d\n", yearStats.get_score());
                    System.out.printf("Total distance: %.1f\n", yearStats.get_distance());
                    this.present();
                }),
                new MenuOption("view course statistics", () -> {
                    Statistics baseStats = new LifetimeStats(golfer);
                    Statistics yearStats = getUserYear(baseStats);
                    Statistics courseStats = getUserCourse(yearStats);

                    System.out.printf("Total swings: %d\n", courseStats.get_score());
                    System.out.printf("Total distance: %.1f\n", courseStats.get_distance());
                    this.present();
                }),
                new MenuOption("view round statistics", () -> {
                    Statistics baseStats = new LifetimeStats(golfer);
                    Statistics yearStats = getUserYear(baseStats);
                    Statistics courseStats = getUserCourse(yearStats);
                    Statistics roundStats = getUserRound(courseStats);
                    
                    System.out.printf("Total swings: %d\n", roundStats.get_score());
                    System.out.printf("Total distance: %.1f\n", roundStats.get_distance());
                }),
                new MenuOption("view hole statistics", () -> {
                    Statistics baseStats = new LifetimeStats(golfer);
                    Statistics yearStats = getUserYear(baseStats);
                    Statistics courseStats = getUserCourse(yearStats);
                    Statistics roundStats = getUserRound(courseStats);
                    Statistics holeStats = getUserHole(roundStats);
                    
                    System.out.printf("Total swings: %d\n", holeStats.get_score());
                    System.out.printf("Total distance: %.1f\n", holeStats.get_distance());
                })
        );
    }
}