-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExerciseIntervalTimer.java
207 lines (163 loc) · 7.45 KB
/
ExerciseIntervalTimer.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
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
import java.util.ArrayList;
import java.util.Scanner;
//Timer idea from:
//https://www.youtube.com/watch?v=qeJXCL6qRQA&list=PLnklCwfTPmxys0fMybXcqUVke7VDjLf7-&index=7
public class ExerciseIntervalTimer {
public static void main(String[] args) throws InterruptedException{
Scanner scnr = new Scanner(System.in);
//Variables
boolean continuing = true;
boolean continuing2 = true;
int count = 1;
boolean end = false;
//Lists
ArrayList exerciseList = new ArrayList();
ArrayList exerciseListSeconds = new ArrayList();
String exerciseListOutput = "";
System.out.println("Welcome to the Exercise Interval Timer!");
//Loop of Entire Program
while (!end) {
//Startup Loop
while (continuing) {
System.out.println("\nTo add an exercise, enter \"a\"");
System.out.println("To continue, enter \"z\"");
System.out.println("To quit the program, enter \"q\"");
String startInput = scnr.nextLine();
//Add exercise
if (startInput.equals("a")) {
System.out.println("\nEnter the name of exercise " + count + ".");
System.out.println("To add a break, enter \"b\"");
System.out.println("To go back, enter \"q\"");
String nameInput = scnr.nextLine();
//Breaks
if (nameInput.equals("b")) {
exerciseList.add("Break");
System.out.println("\nHow many seconds?");
try {
int secondsInput = scnr.nextInt();
exerciseListSeconds.add(secondsInput);
count++;
}
catch (Exception e){
System.out.println("\nPlease enter an integer.");
}
nameInput = scnr.nextLine();
}
//Exercises
else if (!(nameInput.equals("q"))) {
exerciseList.add(nameInput);
System.out.println("\nHow many seconds?");
try {
int secondsInput = scnr.nextInt();
exerciseListSeconds.add(secondsInput);
count++;
}
catch (Exception e){
System.out.println("\nPlease enter an integer.");
}
nameInput = scnr.nextLine();
}
}
//Continue
else if (startInput.equals("z")) {
if (count < 2) {
System.out.println("\nEnter at least 1 exercise before continuing.");
}
else {
for (int c = 1; c < count; c++) {
exerciseListOutput = exerciseListOutput + c + ". " + exerciseList.get(c - 1) + " for " + exerciseListSeconds.get(c - 1) + " seconds.\n";
}
continuing = false;
}
}
//End Program
else if (startInput.equals("q")) {
System.exit(0);
}
else {
System.out.println("\nInvalid response.");
}
}
//Exercise Editor
while (continuing2) {
System.out.println("\nHere is the list of exercises: ");
System.out.println(exerciseListOutput);
System.out.println("To start the exercise timer, enter \"s\"");
System.out.println("To delete an exercise, enter \"d\"");
String start = scnr.nextLine();
//Start Timer
if (start.equals("s")) {
count--;
continuing2 = false;
}
//Delete Exercise
else if (start.equals("d")) {
if (count == 2) {
System.out.println("\nYou only have one exercise to delete.");
}
else {
System.out.println("\nWhich # exercise would you like to delete?");
try {
int exerciseDelete = scnr.nextInt();
exerciseList.remove(exerciseDelete - 1);
exerciseListSeconds.remove(exerciseDelete - 1);
count--;
exerciseListOutput = "";
for (int c = 1; c < count; c++) {
exerciseListOutput = exerciseListOutput + c + ". " + exerciseList.get(c - 1) + " for " + exerciseListSeconds.get(c - 1) + " seconds.\n";
}
start = scnr.nextLine();
}
catch (Exception e) {
System.out.println("Invalid response.\n");
}
}
}
else {
System.out.println("\nInvalid response.");
}
}
//Countdown to start
System.out.println("\nStarting in 3...");
Thread.sleep(1000);
System.out.println("2...");
Thread.sleep(1000);
System.out.println("1...");
Thread.sleep(1000);
System.out.println("Go!");
Thread.sleep(1000);
//Interval Timer
for (int c = 0; c < count; c++) {
System.out.println("\n" + exerciseList.get(c) + " for " + (int) (exerciseListSeconds.get(c)) + " seconds.");
String breakChecker = (String) exerciseList.get(c);
//Break Encouragement
if (breakChecker.equals("Break")) {
int random = (int) (Math.random() * 4);
if (random == 0){
System.out.println("Don't give up!");
}
else if (random == 1){
System.out.println("Keep pushing!");
}
else if (random == 2){
System.out.println("Don't forget to breathe.");
}
else {
System.out.println("You're doing great!");
}
}
//Exercise Countdown
for (int d = (int) (exerciseListSeconds.get(c)); d > 0; d--) {
System.out.println(d);
Thread.sleep(1000);
}
}
System.out.println("\nWell done!");
//Reset Variables
continuing = true;
continuing2 = true;
exerciseListOutput = "";
count++;
}
}
}