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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
package view;

import controller.DietController;
import model.BasicFood;
import model.DietLog;
import model.Exercise;
import model.Food;

import java.io.Console;
import java.util.ArrayList;
import java.util.Map;
import java.util.Scanner;

public class DietView {

    DietController dc;
    ViewMediator viewMediator;
    Scanner scan = new Scanner(System.in);
    String[] foodInfo = new String[5];
    String selectedDate = "";
    boolean todaySelected = true;

    public DietView() {
        dc = new DietController();
        viewMediator = new ViewMediator();
        DietManagerFrame dietManagerFrame = new DietManagerFrame("Diet Manager", dc, viewMediator);
        System.out.println("Welcome to Diet Manager!\n");
        selectedDate = dc.getCurrentDate();
        introMessage();
        initPromptUser();
    }

    private void introMessage() {
        System.out.println("Current Diet Log Date: " + selectedDate);
        System.out.println("Please select numbers between 1-9 to execute desired functionality");
        System.out.println("1: Add a food\n2: Add a Recipe\n3: Log a Food\n4: Set Daily Goals\n5: Set Current Weight\n6: View Log\n7: Remove Food from Log \n8: Add an Exercise \n9: Log an Exercise \n10: Remove Exercise from log \n11: Change Date\n12: Save\n13: Exit\n");
        System.out.print("Please enter a number: ");
    }

    private void initPromptUser() {
        String userInput = "";
        while((userInput = scan.nextLine()) != "") {
            try {
                int input = Integer.parseInt(userInput);

                switch (input) {
                    case 1:
                        buildFood();
                        break;
                    case 2:
                        buildRecipe();
                        break;
                    case 3:
                        logFood();
                        break;
                    case 4:
                        setGoals();
                        break;
                    case 5:
                        setPersonalInfo();
                        break;
                    case 6:
                        getLogInfo(selectedDate);
                        break;
                    case 7:
                        removeFoodFromLog();
                        break;
                    case 8:
                        buildExercise();
                        break;
                    case 9:
                        logExercise();
                        break;
                    case 10:
                        removeExerciseFromLog();
                        break;
                    case 11:
                        changeDate();
                    case 12:
                        System.out.println("Saving...");
                        dc.writeCSV();
                        System.out.println("Your data has been saved!");
                        break;
                    case 13:
                        dc.writeCSV();
                        System.out.println("Thanks for using Diet Manager! Have a great day! :)");
                        System.exit(0);
                    default:
                        System.out.println("Not a valid number");
                        break;
                }
                System.out.print("\n");
                introMessage();
            } catch (NumberFormatException nfe) {
                System.out.println("Please Enter a valid number");
            }
        }
    }

    private void buildExercise(){
        printExerciseList();
        String exerciseElement;
        String exerciseName;
        double caloriesBurned;

        System.out.println("Name of Exercise: ");
        exerciseElement = scan.nextLine();
        exerciseName = exerciseElement;

        while(dc.searchExerciseList(exerciseName.toLowerCase()) != null) { // food already exists by that name in the list
            System.out.println("Sorry, that Exercise already exists in the system.");
            System.out.print("Enter q to quit or please enter another name: ");
            exerciseName = scan.nextLine();
            if(exerciseName.equals("q")) {
                System.out.print("\n");
                return;
            }
        }

        // Calories Burned entry
        System.out.print("Calories Burned for a 100 pound person: ");
        while(!scan.hasNextDouble()) {
            System.out.println("Calories Burned must be a number (ex. 180.0)");
            System.out.print("Please enter a number: ");
            scan.nextLine();
        }
        exerciseElement = scan.nextLine();
        caloriesBurned = Double.parseDouble(exerciseElement);

        dc.addExercise(exerciseName, caloriesBurned);
    }

    public void printExerciseList() {
        System.out.println("=======================AVAILABLE Exercises=======================");
        for(String k : dc.getExerciseNames()) {
            System.out.println(k);
        }
        System.out.print("\n");
    }

    private void buildFood() {
        printFoodList();
        String foodElement;
        String name;
        int calories;

        double carbs;
        double protein;
        double fats;

        System.out.print("Name of Food: ");
        foodElement = scan.nextLine();
        name = foodElement;

        // Here we will need to use the dietController to return us the FoodList list
        // then check the name passed against food list that was returned
        // before the user begins to fill out anything

        while(dc.searchFoodList(name.toLowerCase()) != null) { // food already exists by that name in the list
            System.out.println("Sorry, that food already exists in the system.");
            System.out.print("Enter q to quit or please enter another name: ");
            name = scan.nextLine();
            if(name.equals("q")) {
                System.out.print("\n");
                return;
            }
        }

        // Calorie entry
        System.out.print("Calories: ");
        while(!scan.hasNextInt()) {
            System.out.println("Calories must be a whole number");
            System.out.print("Please enter a number: ");
            scan.nextLine();
        }
        foodElement = scan.nextLine();
        calories = Integer.parseInt(foodElement);

        // Fat entry
        System.out.print("Fat: ");
        while(!scan.hasNextDouble()) {
            System.out.println("Please enter a valid number. Ex.) 10.5");
            System.out.print("Please try again: ");
            scan.nextLine();
        }
        foodElement = scan.nextLine();
        fats = Double.parseDouble(foodElement);


        // Carb entry
        System.out.print("Carbs: ");
        while(!scan.hasNextDouble()) {
            System.out.println("Please enter a valid number. Ex.) 10.5");
            System.out.print("Please try again: ");
            scan.nextLine();
        }
        foodElement = scan.nextLine();
        carbs = Double.parseDouble(foodElement);

        // Protein entry
        System.out.print("Protein: ");
        while(!scan.hasNextDouble()) {
            System.out.println("Please enter a valid number. Ex.) 10.5");
            System.out.print("Please try again: ");
            scan.nextLine();
        }
        foodElement = scan.nextLine();
        protein = Double.parseDouble(foodElement);

        dc.addBasicFood(name, calories, fats, carbs, protein );

        System.out.println("Your food has been added!");
    }

    private void buildRecipe() {

        String userInput;
        String name;
        String food;
        String servings;
        Boolean finishRecipe = false;
        ArrayList<String> recipeList = new ArrayList<String>();
        ArrayList<String> servingList = new ArrayList<String>();

        System.out.print("Please enter the recipe name: ");
        userInput = scan.nextLine();
        name = userInput;

        // Loops of the recipe already exists
        while ( dc.searchFoodList( name.toLowerCase() ) != null ) {

            System.out.println("Recipe can not be created - recipe already exists!");
            System.out.print("Please enter another recipe name, or enter 'q' to quit: ");
            name = scan.nextLine();

            if ( name.equals("q") ) {

                System.out.print("\n");
                return;

            }

        }

        // Prints the entire list of foods
        printFoodList();

        System.out.print("Please enter the name of the food from the list above to add to your recipe: ");
        userInput = scan.nextLine();
        food = userInput;

        while ( !finishRecipe ) {

            // Loops if the food entered does not exist
            while ( dc.searchFoodList( food.toLowerCase() ) == null ) {

                System.out.println("Food can not be added - food does not exist!");
                System.out.print("Please enter another food, or enter 'q' to quit: ");
                food = scan.nextLine();

                if ( food.equals("q") ) {

                    System.out.print("\n");
                    return;

                }

            }

            System.out.print("Please enter the number of servings present in the recipe: ");

            // Checks if the user entered a valid input
            while( !scan.hasNextDouble() ) {

                System.out.println("Invalid entry - must enter a number");
                System.out.print("Please try again: ");
                scan.next();

            }

            userInput = scan.nextLine();
            servings = userInput;

            // Adds the string name and servings of the food to the arrayList
            recipeList.add(food);
            servingList.add(servings);
            System.out.println("Food added to recipe!");

            System.out.print("Enter another food, or enter 'q' to quit and save recipe: ");
            userInput = scan.nextLine();
            food = userInput;

            // If the user chooses to quit, the recipe is added to the list and the loop ends
            if ( food.equals("q") ) {

                System.out.print("\n");
                dc.addRecipe(name, recipeList, servingList);
                System.out.println("Recipe saved!!");
                finishRecipe = true;

            }

        }

    }

    public void printFoodList() {
        System.out.println("=======================AVAILABLE FOODS=======================");
        for(String k : dc.getFoodListKeys()) {
            System.out.println(k);
        }
        System.out.print("\n");
    }

    private double getDoubleInput(String message) {
        String inputString;
        double inputDouble;
        System.out.print(message);
        while(!scan.hasNextDouble()) {
            System.out.println("Please enter a valid number. Ex.) 10.5");
            System.out.print("Please try again: ");
            scan.nextLine();
        }
        inputString = scan.nextLine();
        inputDouble = Double.parseDouble(inputString);
        return inputDouble;
    }

    private int getIntInput(String message) {
        String inputString;
        int inputInt;
        System.out.print(message);
        while(!scan.hasNextInt()) {
            System.out.println("Please enter a valid number. Ex.) 10");
            System.out.print("Please try again: ");
            scan.next();
        }
        inputString = scan.nextLine();
        inputInt = Integer.parseInt(inputString);
        return inputInt;
    }

    private void logFood() {
        String foodElement;
        String name;
        double servingCount;

        System.out.print("\n");
        printFoodList();

        //food name entry
        System.out.print("Name of Food: ");
        foodElement = scan.nextLine();
        name = foodElement;

        while(dc.searchFoodList(name.toLowerCase()) == null) {
            System.out.println("Sorry, that food does not exist in the system.");
            System.out.print("Enter q to quit or please enter another name: ");
            name = scan.nextLine();
            if(name.equals("q")) {
                System.out.print("\n");
                return;
            }
        }

        //serving count entry
        System.out.print("Number of Servings: ");
        while(!scan.hasNextDouble()) {
            System.out.println("Please enter a valid number. Ex.) 10.5");
            System.out.print("Please try again: ");
            scan.nextLine();
        }
        foodElement = scan.nextLine();
        servingCount = Double.parseDouble(foodElement);

        dc.logFood(name, servingCount, selectedDate);
        System.out.println("Your food has been logged!");
    }

    private void logExercise(){
        String exerciseElement;
        String name;
        double time;

        System.out.print("\n");
        printExerciseList();

        //exercise name entry
        System.out.print("Name of Exercise: ");
        exerciseElement = scan.nextLine();
        name = exerciseElement;

        while(dc.searchExerciseList(name.toLowerCase()) == null) {
            System.out.println("Sorry, that exercise does not exist in the system.");
            System.out.print("Enter q to quit or please enter another name: ");
            name = scan.nextLine();
            if(name.equals("q")) {
                System.out.print("\n");
                return;
            }
        }

        //serving count entry
        System.out.print("Duration of exercise (in minutes): ");
        while(!scan.hasNextDouble()) {
            System.out.println("Please enter a valid number. Ex.) 10.5");
            System.out.print("Please try again: ");
            scan.nextLine();
        }
        exerciseElement = scan.nextLine();
        time = Double.parseDouble(exerciseElement);

        dc.logExercise(name, time, selectedDate);
        System.out.println("Your exercise has been logged!");

    }

    private void setGoals() {
        double calorieGoal = getDoubleInput("Daily Calorie Limit: ");
        double weightGoal = getDoubleInput("Daily Weight Goal (lbs.): ");
        dc.setUserGoals(calorieGoal, weightGoal, selectedDate);
        System.out.println("Your goals have been updated!");
    }

    private void setPersonalInfo() {
        double weight = getDoubleInput("Current Weight (lbs.): ");
        dc.setPersonalInfo(weight, selectedDate);
        System.out.println("Your weight has been updated!");
    }

    private void printNumberedFoodListWithServings(ArrayList<Food> foodList) {
        for(int i = 1; i<=foodList.size(); i++) {
            Food food = foodList.get(i-1);
            System.out.println(i + ".) " + food.getName() + " - " + food.getServing() + " servings");
        }
    }

    private void printExercisesWithTimes(ArrayList<Exercise> exerciseList){
        for(int i = 1; i <= exerciseList.size(); i++){
            Exercise exer = exerciseList.get(i-1);
            System.out.println(i + ".) " + exer.getName() + " - " + exer.getCaloriesBurned());
        }
    }

    private void removeFoodFromLog() {
        ArrayList<Food> foodList = dc.getTodaysLogList();
        System.out.println("Food Log for current day: ");
        printNumberedFoodListWithServings(foodList);
        int intInput = getIntInput("Please enter the number for the food entry you wish to remove:");
        dc.removeFoodFromLog(intInput-1);
        System.out.println("Successfully removed entry from log!");
    }

    private void removeExerciseFromLog(){
        ArrayList<Exercise> exerciseList = dc.getTodaysExerciseLogList();
        System.out.println("Exercise Log for current day: ");
        printExercisesWithTimes(exerciseList);
        int intInput = getIntInput("Please enter the number for the exercise entry you wish to remove:");
        dc.removeExerciseFromLog(intInput-1);
        System.out.println("Successfully removed entry from log!");
    }

    private String getDateFromUser() {
        System.out.print("Please Enter A Date yyyy/mm/dd: ");
        String date = scan.nextLine();
        //while((date = scan.nextLine()) != "") {
        // some kind of validation here. regex?
        // needs to be in format yyyy/mm/dd
        //return date;
        //}
        return date;
    }

    private void getLogInfo(String date) {
        // run function in diet controller to return all nutritional info?
        DietLog desiredLog = dc.getDesiredDietLog(date);
        int totalCalories = desiredLog.getTotalCalories();
        double totalCaloriesBurned = desiredLog.getTotalCaloriesBurned();
        double dailyLimit = desiredLog.getDailyLimit();
        double weight = desiredLog.getDailyWeight();
        double fatPerc = desiredLog.getFatPerc();
        double carbPerc = desiredLog.getCarbPerc();
        double proteinPerc = desiredLog.getProteinPerc();
        double netCals = desiredLog.getNetCals();

        System.out.println("=======================LOGGED INFO FOR DATE=======================");
        System.out.println("Weight: " + weight + " lbs");
        System.out.println("Calorie Limit: " + dailyLimit);
        System.out.println("Total Calories Consumed: " + totalCalories);
        System.out.println("Total Calories Burned: " + totalCaloriesBurned);
        System.out.println("Fat Percentage: " + fatPerc + "%");
        System.out.println("Carb Percentage: " + carbPerc + "%");
        System.out.println("Protein Percentage: " + proteinPerc + "%");

        double calsLeft = desiredLog.calcCalDiff();
        if(calsLeft >= 0) {
            System.out.println("You have " + calsLeft + " calories left!");
        }
        else {
            double exceededCals = totalCalories - dailyLimit;
            System.out.println("You have exceeded your caloric limit by " + exceededCals + " calories!");
        }

        // print out all foods eaten for day.
        for(String foodInfo : desiredLog.getFoodInfo()) {
            System.out.println(foodInfo);
        }

        for(String exerInfo: desiredLog.getExerciseInfo()){
            System.out.println(exerInfo);
        }
    }

    private void changeDate() {
        System.out.print("\nPlease enter a date (enter 'today' to change to today's date, or 'q' to go back): ");
        String input = scan.nextLine();

        while (input.equals("")) {
            input = scan.nextLine();
        }

        switch (input) {
            case "q":
                return;

            case "today":
                selectedDate = dc.getCurrentDate();
                todaySelected = true;
                break;

            default:
                selectedDate = input;
                todaySelected = false;
                break;
        }
    }
}