This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFrontend.java
165 lines (144 loc) · 4.77 KB
/
Frontend.java
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
import java.io.File;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Scanner;
public class Frontend {
// fields
private Scanner input;
public Frontend(Scanner input) {
this.input = input;
}
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
//Frontend frontend = new Frontend(scnr);
System.out.println("Hello! Welcome to the Diet Plan App!");
try {
//File textFile = new File("file.txt");
PrintWriter print = new PrintWriter("file.txt");
print.println(getAge());
print.println(getGender());
print.println(getWeight());
print.println(getHeight());
print.println(getDietaryRestrictions());
print.println(getActivityAmount());
print.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static int getAge() {
int age = -1;
while (age == -1) {
System.out.println("Please enter your age (between 15 and 80): ");
Scanner scnr = new Scanner(System.in);
if (scnr.hasNextInt()) {
age = scnr.nextInt();
if (age < 15 || age > 80) {
getAge();
}
}
}
return age;
}
public static int getGender() {
int gender = 0;
while (gender == 0) {
System.out.println("Please indicate the number of your biological gender (1. (female), 2. (male): ");
Scanner scnr = new Scanner(System.in);
if (scnr.hasNextInt()) {
gender = scnr.nextInt();
if (gender != 1 && gender != 2) {
getGender();
}
}
}
return gender;
}
public static int getWeight() {
String input = null;
int weight = 0;
double doubleWeight = 0.0;
while (input == null) {
System.out.println("Are you using pounds or kilograms for weight?: ");
Scanner scnr = new Scanner(System.in);
if (scnr.hasNext()) {
input = scnr.nextLine().trim();
if (!input.equals("pounds") && !input.equals("kilograms")) {
getWeight();
} else {
do {
System.out.println("Please enter your weight (above 0): ");
if (scnr.hasNextDouble()) {
doubleWeight = scnr.nextDouble();
}
}
while (doubleWeight <= 0.0);
if (input.equals("pounds")) {
doubleWeight = doubleWeight * 0.45359237;
weight = (int) doubleWeight;
}
}
}
}
return weight;
}
public static int getHeight() {
String input = null;
int height = 0;
double doubleHeight = 0.0;
while (input == null) {
System.out.println("Are you using feet or centimeters for your height?: ");
Scanner scnr = new Scanner(System.in);
if (scnr.hasNext()) {
input = scnr.nextLine().trim();
if (!input.equals("feet") && !input.equals("centimeters")) {
getHeight();
} else {
do {
System.out.println("Please enter your height (above 0): ");
if (scnr.hasNextDouble()) {
doubleHeight = scnr.nextDouble();
}
}
while (doubleHeight <= 0.0);
if (input.equals("feet")) {
doubleHeight = doubleHeight * 30.48;
height = (int) doubleHeight;
}
}
}
}
return height;
}
public static int getDietaryRestrictions() {
int restriction = 0;
while (restriction == 0) {
System.out.println("What are your dietary restrictions? (1. no restrictions, 2. vegetarian, 3. vegan, 4. gluten-free, "
+ "5. dairy-free): ");
Scanner scnr = new Scanner(System.in);
if (scnr.hasNext()) {
restriction = scnr.nextInt();
if (restriction != 1 && restriction != 2 && restriction != 3
&& restriction != 4 && restriction != 5) {
getDietaryRestrictions();
}
}
}
return restriction;
}
public static int getActivityAmount() {
int activity = 0;
while (activity == 0) {
System.out.println("Please enter your activity amount (choose number): "
+ "\n1. Sedentary (little/no exercise)\nLight (exercsie 1-3x/week)"
+ "\n2. Moderate (exercise 4-5x/week)\nActive (daily/intense exercise 3-4x/week"
+ "\n3. Very Active (intense exercise 6-7x/week"
+ "\n4. Extra Active (very intense exercise daily/physical job");
Scanner scnr = new Scanner(System.in);
if (scnr.hasNextInt()) {
activity = scnr.nextInt();
}
}
return activity;
}
}