From 32b4e52b5334a3776eefe04abc9358f43b387786 Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Fri, 6 Mar 2026 15:01:43 -0500 Subject: [PATCH 01/16] Feat: added uml diagram --- src/main/java/diagram.puml | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/main/java/diagram.puml diff --git a/src/main/java/diagram.puml b/src/main/java/diagram.puml new file mode 100644 index 0000000..132fc1c --- /dev/null +++ b/src/main/java/diagram.puml @@ -0,0 +1,77 @@ +@startuml + +Class FitnessApp{ ++ startApp(): void +} + +Class Person{ +- name: String +- email: String +- workouts: ArrayList + ++ getName(): String ++ setName(name: String): void + ++ getEmail(): String ++ setEmail(email: String): void + ++ getWorkouts(): ArrayList ++ setWorkouts(workouts: ArrayList): void +} + +Class Workout{ +- duration: String +- date: Date +- completed: boolean +- exercise: ArrayList + ++ getDuration(): String ++ setDuration(duration: String): void + ++ getDate(): Date ++ setDate(date: Date): void + ++ getCompleted(): boolean ++ setCompleted(completed: boolean): void + ++ getExercise(): ArrayList ++ setExercise(exercise: ArrayList): void + ++ displayWorkoutInfo(): void +} + +Class Exercise{ +- type: WorkoutType +- name: String +- caloriesBurned: double + ++ getType(): WorkoutType ++ setType(type: WorkoutType): void + ++ getCaloriesBurned(): double ++ setCaloriesBurned(caloriesBurned: double): void +} + +enum WorkoutType{ +CHEST +BACK +SHOULDER +ARMS +CARDIO +LEGS +} + +' Relationships +FitnessApp "1" --> "*" Person : manages users +' One fitness app can contain multiple people + +Person "1" --> "*" Workout : performs +' A person can complete many workouts + +Workout "1" --> "*" Exercise : contains +' A workout is made up of multiple exercises + +Exercise --> WorkoutType : categorized by +' Each exercise belongs to one workout type + +@enduml \ No newline at end of file From 6f631267a450511ae3630cca26cd15303efc35c9 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Fri, 6 Mar 2026 15:10:31 -0500 Subject: [PATCH 02/16] Initial commit --- src/main/java/org/codedifferently/FitnessApp.java | 8 ++++++++ src/main/java/org/codedifferently/Main.java | 13 ++----------- src/main/java/org/codedifferently/Person.java | 4 ++++ 3 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 src/main/java/org/codedifferently/FitnessApp.java create mode 100644 src/main/java/org/codedifferently/Person.java diff --git a/src/main/java/org/codedifferently/FitnessApp.java b/src/main/java/org/codedifferently/FitnessApp.java new file mode 100644 index 0000000..30d45fa --- /dev/null +++ b/src/main/java/org/codedifferently/FitnessApp.java @@ -0,0 +1,8 @@ +package org.codedifferently; +import java.util.Scanner; + +public class FitnessApp { + public static void startApp(Scanner sc) { + + } +} diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 435139b..f588bad 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,17 +1,8 @@ package org.codedifferently; +import java.util.Scanner; -//TIP To Run code, press or -// click the icon in the gutter. public class Main { public static void main(String[] args) { - //TIP Press with your caret at the highlighted text - // to see how IntelliJ IDEA suggests fixing it. - System.out.printf("Hello and welcome!"); - - for (int i = 1; i <= 5; i++) { - //TIP Press to start debugging your code. We have set one breakpoint - // for you, but you can always add more by pressing . - System.out.println("i = " + i); - } + FitnessApp.startApp(new Scanner(System.in)); } } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/Person.java b/src/main/java/org/codedifferently/Person.java new file mode 100644 index 0000000..07316d0 --- /dev/null +++ b/src/main/java/org/codedifferently/Person.java @@ -0,0 +1,4 @@ +package org.codedifferently; + +public class Person { +} From a26e5489df9caa835d8f8a57a5ec62a1bee1b89e Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Fri, 6 Mar 2026 15:17:46 -0500 Subject: [PATCH 03/16] Implemented Enum --- src/main/java/org/codedifferently/Exercise.java | 4 ++++ src/main/java/org/codedifferently/ExerciseType.java | 10 ++++++++++ src/main/java/org/codedifferently/Person.java | 4 ++++ src/main/java/org/codedifferently/Workout.java | 4 ++++ 4 files changed, 22 insertions(+) create mode 100644 src/main/java/org/codedifferently/Exercise.java create mode 100644 src/main/java/org/codedifferently/ExerciseType.java create mode 100644 src/main/java/org/codedifferently/Workout.java diff --git a/src/main/java/org/codedifferently/Exercise.java b/src/main/java/org/codedifferently/Exercise.java new file mode 100644 index 0000000..b74638f --- /dev/null +++ b/src/main/java/org/codedifferently/Exercise.java @@ -0,0 +1,4 @@ +package org.codedifferently; + +public class Exercise { +} diff --git a/src/main/java/org/codedifferently/ExerciseType.java b/src/main/java/org/codedifferently/ExerciseType.java new file mode 100644 index 0000000..073a747 --- /dev/null +++ b/src/main/java/org/codedifferently/ExerciseType.java @@ -0,0 +1,10 @@ +package org.codedifferently; + +public enum ExerciseType { + CHEST, + BACK, + SHOULDERS, + ARMS, + CARDIO, + LEGS +} diff --git a/src/main/java/org/codedifferently/Person.java b/src/main/java/org/codedifferently/Person.java index 07316d0..35f3420 100644 --- a/src/main/java/org/codedifferently/Person.java +++ b/src/main/java/org/codedifferently/Person.java @@ -1,4 +1,8 @@ package org.codedifferently; +import java.util.ArrayList; public class Person { + private String name; + private String email; + private ArrayList workouts; } diff --git a/src/main/java/org/codedifferently/Workout.java b/src/main/java/org/codedifferently/Workout.java new file mode 100644 index 0000000..f0fd883 --- /dev/null +++ b/src/main/java/org/codedifferently/Workout.java @@ -0,0 +1,4 @@ +package org.codedifferently; + +public class Workout { +} From 1d7bbf46a20d83fd1772c126c141adfb3f57b109 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Fri, 6 Mar 2026 15:19:56 -0500 Subject: [PATCH 04/16] Implemented Person Class --- src/main/java/org/codedifferently/Person.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/org/codedifferently/Person.java b/src/main/java/org/codedifferently/Person.java index 35f3420..b0a981d 100644 --- a/src/main/java/org/codedifferently/Person.java +++ b/src/main/java/org/codedifferently/Person.java @@ -5,4 +5,34 @@ public class Person { private String name; private String email; private ArrayList workouts; + + public Person(String name, String email) { + this.name = name; + this.email = email; + this.workouts = new ArrayList<>(); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public ArrayList getWorkouts() { + return workouts; + } + + public void setWorkouts(ArrayList workouts) { + this.workouts = workouts; + } } From 973aabb94bfe224bfed7be69b4ebb3f9597a19f6 Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Fri, 6 Mar 2026 15:24:21 -0500 Subject: [PATCH 05/16] Feat: created workout class --- .../java/org/codedifferently/Exercise.java | 4 ++ .../java/org/codedifferently/Workout.java | 55 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/main/java/org/codedifferently/Exercise.java create mode 100644 src/main/java/org/codedifferently/Workout.java diff --git a/src/main/java/org/codedifferently/Exercise.java b/src/main/java/org/codedifferently/Exercise.java new file mode 100644 index 0000000..b74638f --- /dev/null +++ b/src/main/java/org/codedifferently/Exercise.java @@ -0,0 +1,4 @@ +package org.codedifferently; + +public class Exercise { +} diff --git a/src/main/java/org/codedifferently/Workout.java b/src/main/java/org/codedifferently/Workout.java new file mode 100644 index 0000000..a803b6c --- /dev/null +++ b/src/main/java/org/codedifferently/Workout.java @@ -0,0 +1,55 @@ +package org.codedifferently; + +import java.util.ArrayList; +import java.util.Date; + +public class Workout { + private String duration; + private Date date; + private boolean completed; + private ArrayList exercises; + + public Workout(String duration, Date date, boolean completed, ArrayList exercises) { + this.duration = duration; + this.date = date; + this.completed = completed; + this.exercises = new ArrayList<>(); + } + + public String getDuration() { + return duration; + } + + public void setDuration(String duration) { + this.duration = duration; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public boolean isCompleted() { + return completed; + } + + public void setCompleted(boolean completed) { + this.completed = completed; + } + + public ArrayList getExercises() { + return exercises; + } + + public void addExercise(Exercise exercise){ + exercises.add(exercise); + } + + public void displayWorkoutInfo(){ + + } + +} From 62ea84d9275b9ecf55c03df4a21749f83531a2a4 Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Fri, 6 Mar 2026 15:34:38 -0500 Subject: [PATCH 06/16] Feat: created workout class --- .../java/org/codedifferently/Exercise.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main/java/org/codedifferently/Exercise.java b/src/main/java/org/codedifferently/Exercise.java index b74638f..541f588 100644 --- a/src/main/java/org/codedifferently/Exercise.java +++ b/src/main/java/org/codedifferently/Exercise.java @@ -1,4 +1,37 @@ package org.codedifferently; public class Exercise { + private WorkoutType type; + private String name; + private int caloriesBurned; + + public Exercise(WorkoutType type, String name, int caloriesBurned) { + this.type = type; + this.name = name; + this.caloriesBurned = caloriesBurned; + } + + public WorkoutType getType() { + return type; + } + + public void setType(WorkoutType type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getCaloriesBurned() { + return caloriesBurned; + } + + public void setCaloriesBurned(int caloriesBurned) { + this.caloriesBurned = caloriesBurned; + } } From 023e7242eb0ba18f1ac877abd45388128758137a Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Fri, 6 Mar 2026 15:55:30 -0500 Subject: [PATCH 07/16] Feat: Added displayWorkoutInfo method to Workout class --- src/main/java/org/codedifferently/Exercise.java | 9 +++++++++ src/main/java/org/codedifferently/Workout.java | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/codedifferently/Exercise.java b/src/main/java/org/codedifferently/Exercise.java index 55d30aa..07bd1aa 100644 --- a/src/main/java/org/codedifferently/Exercise.java +++ b/src/main/java/org/codedifferently/Exercise.java @@ -34,4 +34,13 @@ public int getCaloriesBurned() { public void setCaloriesBurned(int caloriesBurned) { this.caloriesBurned = caloriesBurned; } + + public void displayExerciseInfo() { + System.out.println("Exercise Information"); + System.out.println("--------------------"); + System.out.println("Name: " + name); + System.out.println("Type: " + type); + System.out.println("Calories Burned: " + caloriesBurned); + System.out.println(); + } } diff --git a/src/main/java/org/codedifferently/Workout.java b/src/main/java/org/codedifferently/Workout.java index a803b6c..631efb4 100644 --- a/src/main/java/org/codedifferently/Workout.java +++ b/src/main/java/org/codedifferently/Workout.java @@ -49,7 +49,15 @@ public void addExercise(Exercise exercise){ } public void displayWorkoutInfo(){ - + System.out.println("******************************"); + System.out.println("\nWorkout Date " + date); + System.out.println("Duration: " + duration); + System.out.println("Status: " + completed); + + for (Exercise exercise : exercises) { + System.out.println(exercise); + } + System.out.println("******************************"); } } From c6a02999f95910c18db4247018856a4a08c5a3bc Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Fri, 6 Mar 2026 15:56:44 -0500 Subject: [PATCH 08/16] Feat: Added displayExerciseInfo method to Exercise class --- src/main/java/org/codedifferently/Exercise.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/codedifferently/Exercise.java b/src/main/java/org/codedifferently/Exercise.java index 07bd1aa..11e184d 100644 --- a/src/main/java/org/codedifferently/Exercise.java +++ b/src/main/java/org/codedifferently/Exercise.java @@ -36,8 +36,8 @@ public void setCaloriesBurned(int caloriesBurned) { } public void displayExerciseInfo() { - System.out.println("Exercise Information"); System.out.println("--------------------"); + System.out.println("Exercise Information"); System.out.println("Name: " + name); System.out.println("Type: " + type); System.out.println("Calories Burned: " + caloriesBurned); From 35e35be95189e7eb21e6185de0a7da9fbe549f6c Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Fri, 6 Mar 2026 16:04:06 -0500 Subject: [PATCH 09/16] Implemented signup --- .../java/org/codedifferently/FitnessApp.java | 120 ++++++++++++++++++ src/main/java/org/codedifferently/Person.java | 12 +- .../java/org/codedifferently/Workout.java | 1 - 3 files changed, 131 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/codedifferently/FitnessApp.java b/src/main/java/org/codedifferently/FitnessApp.java index 30d45fa..fe71f81 100644 --- a/src/main/java/org/codedifferently/FitnessApp.java +++ b/src/main/java/org/codedifferently/FitnessApp.java @@ -1,8 +1,128 @@ package org.codedifferently; +import java.util.ArrayList; import java.util.Scanner; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class FitnessApp { + private static ArrayList users = new ArrayList<>(); public static void startApp(Scanner sc) { + System.out.println("Welcome to LiftLogic!"); + int input; + // Stores appointment data for generating a journal upon exit. + + do { + // Displays the main menu options to the user. + System.out.println("\n=== Barber Shop Management Menu ==="); + System.out.println("1) Signup"); + System.out.println("2) Login"); + System.out.println("0) Quit"); + System.out.print("Choose: "); + + // Validates numeric input before processing. + if (sc.hasNextInt()) { + input = sc.nextInt(); + } else { + input = -1; + } + sc.nextLine(); + + String name; + String phoneNumber; + + switch (input) { + // Handles the creation and storage of a new customer. + case 1: + signup(sc); + break; + // Displays the full list of registered customers. + case 2: + Person toLogin = validateLogin(sc); + if (toLogin != null) { + login(toLogin); + } else { + System.out.println("Invalid username or password. Try again."); + } + break; + // Exits the system and prints a journal of completed appointments. + case 0: + System.out.println("\nExiting system..."); + break; + // Handles invalid menu selections. + default: + System.out.println("\nPlease select a valid option."); + } + // Stopping condition. Program will exit when the user inputs 0. + } while (input != 0); + } + + private static void signup(Scanner sc) { + String name = validateName(sc); + String email = validateEmail(sc); + System.out.print("Enter a password: "); + String password = sc.nextLine(); + Person user = new Person(name, email, password); + users.add(user); + FitnessApp.login(user); + } + + public static void login(Person person) { + + } + + // Searches for a customer using their phone number and returns the match if found. + public static Person validateLogin(Scanner sc) { + String email = validateEmail(sc); + System.out.print("Enter your password: "); + String password = sc.nextLine(); + + for (Person user : FitnessApp.getUsers()) { + if (user.getEmail().equals(email) && user.getPassword().equals(password)) { + return user; + } + } + return null; + } + + // Validates that the user's name input contains only permitted characters. + public static String validateName(Scanner sc) { + // Repeats continuously until valid input is provided. + while (true) { + // Prompts the user to enter their name. + System.out.print("\nEnter a name: "); + String name = sc.nextLine(); + + // Checks whether the input matches the required name pattern. + // Allows letters and optionally single spaces, hyphens, or apostrophes between words. + if (name.matches("^[a-zA-Z]+([ '-][a-zA-Z]+)*$")) { + // Returns the validated name if it meets the pattern requirements. + return name; + } else { + // Displays an error message if validation fails. + System.out.println("\nInvalid name. Please use letters only."); + } + } + } + + public static String validateEmail(Scanner sc) { + // Prompts the user for a valid email address for the order. Will launch an error if it is invalid. + while (true) { + System.out.print("Enter your email address?: "); + String email = sc.nextLine(); + try { + if (!email.matches("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$")) { + throw new IllegalArgumentException(); + } else { + return email; + } + } catch (IllegalArgumentException e) { + System.out.println("\nInvalid email address. Try again.\n"); + } + } + } + + public static ArrayList getUsers() { + return users; } } diff --git a/src/main/java/org/codedifferently/Person.java b/src/main/java/org/codedifferently/Person.java index b0a981d..4d33aee 100644 --- a/src/main/java/org/codedifferently/Person.java +++ b/src/main/java/org/codedifferently/Person.java @@ -4,11 +4,13 @@ public class Person { private String name; private String email; + private String password; private ArrayList workouts; - public Person(String name, String email) { + public Person(String name, String email, String password) { this.name = name; this.email = email; + this.password = password; this.workouts = new ArrayList<>(); } @@ -35,4 +37,12 @@ public ArrayList getWorkouts() { public void setWorkouts(ArrayList workouts) { this.workouts = workouts; } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } } diff --git a/src/main/java/org/codedifferently/Workout.java b/src/main/java/org/codedifferently/Workout.java index a803b6c..733a5b9 100644 --- a/src/main/java/org/codedifferently/Workout.java +++ b/src/main/java/org/codedifferently/Workout.java @@ -51,5 +51,4 @@ public void addExercise(Exercise exercise){ public void displayWorkoutInfo(){ } - } From a2bb6bc72846ad165a7ea61c765ec90b23b77d00 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Fri, 6 Mar 2026 16:53:32 -0500 Subject: [PATCH 10/16] Finished most of initial fitness app implementation --- .../java/org/codedifferently/FitnessApp.java | 159 +++++++++++++++++- src/main/java/org/codedifferently/Person.java | 9 + .../java/org/codedifferently/Workout.java | 12 +- 3 files changed, 160 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/codedifferently/FitnessApp.java b/src/main/java/org/codedifferently/FitnessApp.java index fe71f81..9171378 100644 --- a/src/main/java/org/codedifferently/FitnessApp.java +++ b/src/main/java/org/codedifferently/FitnessApp.java @@ -1,8 +1,7 @@ package org.codedifferently; import java.util.ArrayList; +import java.util.Date; import java.util.Scanner; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public class FitnessApp { private static ArrayList users = new ArrayList<>(); @@ -14,7 +13,7 @@ public static void startApp(Scanner sc) { do { // Displays the main menu options to the user. - System.out.println("\n=== Barber Shop Management Menu ==="); + System.out.println("\n=== LiftLogic ==="); System.out.println("1) Signup"); System.out.println("2) Login"); System.out.println("0) Quit"); @@ -28,9 +27,6 @@ public static void startApp(Scanner sc) { } sc.nextLine(); - String name; - String phoneNumber; - switch (input) { // Handles the creation and storage of a new customer. case 1: @@ -40,7 +36,7 @@ public static void startApp(Scanner sc) { case 2: Person toLogin = validateLogin(sc); if (toLogin != null) { - login(toLogin); + login(toLogin, sc); } else { System.out.println("Invalid username or password. Try again."); } @@ -64,11 +60,156 @@ private static void signup(Scanner sc) { String password = sc.nextLine(); Person user = new Person(name, email, password); users.add(user); - FitnessApp.login(user); + FitnessApp.login(user, sc); } - public static void login(Person person) { + public static void login(Person person, Scanner sc) { + System.out.println("Welcome, " + person.getName() + "!"); + int input; + + do { + // Displays the main menu options to the user. + System.out.println("\n=== LiftLogic ==="); + System.out.println("1) Log a workout"); + System.out.println("2) Display Leaderboard"); + System.out.println("3) Settings"); + System.out.println("0) Logout"); + System.out.print("Choose: "); + // Validates numeric input before processing. + if (sc.hasNextInt()) { + input = sc.nextInt(); + } else { + input = -1; + } + sc.nextLine(); + + switch (input) { + // Handles the creation and storage of a new customer. + case 1: + Workout workout = createWorkout(sc); + ArrayList workouts = person.getWorkouts(); + workouts.add(workout); + person.setWorkouts(workouts); + person.setActiveWorkout(workout); + break; + // Displays the full list of registered customers. + case 2: + break; + // Exits the system and prints a journal of completed appointments. + case 3: + displaySettings(person, sc); + break; + case 0: + System.out.println("\nLogging out..."); + break; + // Handles invalid menu selections. + default: + System.out.println("\nPlease select a valid option."); + } + // Stopping condition. Program will exit when the user inputs 0. + } while (input != 0); + } + + public static void displaySettings(Person person, Scanner sc) { + int input; + do { + System.out.println("\n=== Settings ==="); + System.out.println("1) Change Name"); + System.out.println("2) Reset Password"); + System.out.println("0) Exit"); + System.out.print("Choose: "); + + // Validates numeric input before processing. + if (sc.hasNextInt()) { + input = sc.nextInt(); + } else { + input = -1; + } + sc.nextLine(); + + switch (input) { + // Handles the creation and storage of a new customer. + case 1: + String name = validateName(sc); + person.setName(name); + break; + // Displays the full list of registered customers. + case 2: + System.out.print("Enter your current password: "); + String password = sc.nextLine(); + if (person.getPassword().equals(password)) { + System.out.print("Enter your new password: "); + String pass1 = sc.nextLine(); + System.out.print("Enter your new password again: "); + String pass2 = sc.nextLine(); + + if (pass1.equals(pass2)) { + person.setPassword(password); + } else { + System.out.println("Passwords did not match."); + } + } else { + System.out.println("Invalid password."); + } + case 0: + System.out.println("\nExiting settings..."); + break; + // Handles invalid menu selections. + default: + System.out.println("\nPlease select a valid option."); + } + // Stopping condition. Program will exit when the user inputs 0. + } while (input != 0); + } + + public static Workout createWorkout(Scanner scanner) { + System.out.println("Create New Workout"); + + System.out.print("Enter workout duration: "); + String duration = scanner.nextLine(); + + Date date = new Date(); + + Workout workout = new Workout(duration, date, new ArrayList<>()); + + // Ask how many exercises the workout contains + System.out.print("How many exercises are in this workout? "); + int exerciseCount = scanner.nextInt(); + scanner.nextLine(); // clear newline + + for (int i = 0; i < exerciseCount; i++) { + + System.out.println("\nExercise " + (i + 1)); + + // Ask for exercise name + System.out.print("Enter exercise name: "); + String name = scanner.nextLine(); + + // Ask for calories burned + System.out.print("Enter calories burned: "); + int calories = scanner.nextInt(); + scanner.nextLine(); // clear newline + + // Display enum exercise types + System.out.println("Select Exercise Type:"); + + ExerciseType[] types = ExerciseType.values(); + + for (int j = 0; j < types.length; j++) { + System.out.println((j + 1) + ". " + types[j]); + } + + int typeChoice = scanner.nextInt(); + scanner.nextLine(); // clear newline + + ExerciseType selectedType = types[typeChoice - 1]; + + Exercise exercise = new Exercise(selectedType, name, calories); + + workout.addExercise(exercise); + } + return workout; } // Searches for a customer using their phone number and returns the match if found. diff --git a/src/main/java/org/codedifferently/Person.java b/src/main/java/org/codedifferently/Person.java index 4d33aee..bdf67f1 100644 --- a/src/main/java/org/codedifferently/Person.java +++ b/src/main/java/org/codedifferently/Person.java @@ -5,6 +5,7 @@ public class Person { private String name; private String email; private String password; + private Workout activeWorkout = null; private ArrayList workouts; public Person(String name, String email, String password) { @@ -45,4 +46,12 @@ public String getPassword() { public void setPassword(String password) { this.password = password; } + + public Workout getActiveWorkout() { + return activeWorkout; + } + + public void setActiveWorkout(Workout activeWorkout) { + this.activeWorkout = activeWorkout; + } } diff --git a/src/main/java/org/codedifferently/Workout.java b/src/main/java/org/codedifferently/Workout.java index d662cf3..247eaf8 100644 --- a/src/main/java/org/codedifferently/Workout.java +++ b/src/main/java/org/codedifferently/Workout.java @@ -6,13 +6,11 @@ public class Workout { private String duration; private Date date; - private boolean completed; private ArrayList exercises; - public Workout(String duration, Date date, boolean completed, ArrayList exercises) { + public Workout(String duration, Date date, ArrayList exercises) { this.duration = duration; this.date = date; - this.completed = completed; this.exercises = new ArrayList<>(); } @@ -32,13 +30,6 @@ public void setDate(Date date) { this.date = date; } - public boolean isCompleted() { - return completed; - } - - public void setCompleted(boolean completed) { - this.completed = completed; - } public ArrayList getExercises() { return exercises; @@ -52,7 +43,6 @@ public void displayWorkoutInfo(){ System.out.println("******************************"); System.out.println("\nWorkout Date " + date); System.out.println("Duration: " + duration); - System.out.println("Status: " + completed); for (Exercise exercise : exercises) { System.out.println(exercise); From 27aa312a32b8a4942133f49b2536bdf2d4c00a42 Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Fri, 6 Mar 2026 17:01:50 -0500 Subject: [PATCH 11/16] Added helper methods for displaying the leaderboard --- .../java/org/codedifferently/FitnessApp.java | 61 ++++++++++++++++ .../java/org/codedifferently/Workout.java | 71 ++++++++++++++++--- 2 files changed, 123 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/codedifferently/FitnessApp.java b/src/main/java/org/codedifferently/FitnessApp.java index 30d45fa..d098a97 100644 --- a/src/main/java/org/codedifferently/FitnessApp.java +++ b/src/main/java/org/codedifferently/FitnessApp.java @@ -1,8 +1,69 @@ package org.codedifferently; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.Map; import java.util.Scanner; public class FitnessApp { public static void startApp(Scanner sc) { } + + public static Person getMaxKey(Map map) { + int maxExercises = -1; + Person maxPerson = null; + + for (Person person : map.keySet()) { + if (map.get(person) > maxExercises) { + maxExercises = map.get(person); + maxPerson = person; + } + } + + return maxPerson; + } + + public static ArrayList buildLeaderboard(Map map) { + ArrayList leaderboard = new ArrayList<>(); + + while (!map.isEmpty()) { + Person maxPerson = getMaxKey(map); + leaderboard.add(maxPerson); + map.remove(maxPerson); + } + + return leaderboard; + } + + public static int countExercises(Person person) { + int count = 0; + + for (Workout workout : person.getWorkouts()) { + count += workout.getExercises().size(); + } + + return count; + } + + public void displayLeaderboard(ArrayList people) { + + Map map = new LinkedHashMap<>(); + + for (Person person : people) { + int totalExercises = countExercises(person); + map.put(person, totalExercises); + } + + Map copy = new LinkedHashMap<>(map); + + ArrayList leaderboard = buildLeaderboard(copy); + + int rank = 1; + + for (Person person : leaderboard) { + System.out.println(rank + ". " + person.getName() + + " completed " + map.get(person) + " exercises"); + rank++; + } + } } diff --git a/src/main/java/org/codedifferently/Workout.java b/src/main/java/org/codedifferently/Workout.java index 631efb4..0631502 100644 --- a/src/main/java/org/codedifferently/Workout.java +++ b/src/main/java/org/codedifferently/Workout.java @@ -3,61 +3,114 @@ import java.util.ArrayList; import java.util.Date; +/** + * The Workout class represents a workout session. + * It stores information about the workout duration, date, + * completion status, and the exercises performed. + */ public class Workout { + + // Length of the workout (ex: "45 minutes") private String duration; + + // Date the workout occurred private Date date; + + // Indicates whether the workout has been completed private boolean completed; + + // List of exercises included in the workout private ArrayList exercises; - public Workout(String duration, Date date, boolean completed, ArrayList exercises) { + public Workout(String duration, Date date, boolean completed) { this.duration = duration; this.date = date; this.completed = completed; + + // Initialize the exercises list this.exercises = new ArrayList<>(); } + /** + * Gets the workout duration + * @return duration of the workout + */ public String getDuration() { return duration; } + /** + * Sets the workout duration + * @param duration new workout duration + */ public void setDuration(String duration) { this.duration = duration; } + /** + * Gets the date of the workout + * @return workout date + */ public Date getDate() { return date; } + /** + * Sets the date of the workout + * @param date new workout date + */ public void setDate(Date date) { this.date = date; } + /** + * Checks if the workout is completed + * @return true if completed, false otherwise + */ public boolean isCompleted() { return completed; } + /** + * Sets the workout completion status + * @param completed completion status + */ public void setCompleted(boolean completed) { this.completed = completed; } + /** + * Gets the list of exercises in the workout + * @return list of exercises + */ public ArrayList getExercises() { return exercises; } + /** + * Adds a new exercise to the workout + * @param exercise exercise to be added + */ public void addExercise(Exercise exercise){ exercises.add(exercise); } + /** + * Displays detailed information about the workout + * including its exercises. + */ public void displayWorkoutInfo(){ - System.out.println("******************************"); - System.out.println("\nWorkout Date " + date); - System.out.println("Duration: " + duration); - System.out.println("Status: " + completed); + System.out.println("******************************"); + System.out.println("\nWorkout Date: " + date); + System.out.println("Duration: " + duration); + System.out.println("Status: " + completed); - for (Exercise exercise : exercises) { - System.out.println(exercise); + // Loop through each exercise and print it + for (Exercise exercise : exercises) { + System.out.println(exercise); } - System.out.println("******************************"); + + System.out.println("******************************"); } -} +} \ No newline at end of file From f4be7b11888f4f075185eec46c900dae30f0f2bc Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Fri, 6 Mar 2026 17:02:31 -0500 Subject: [PATCH 12/16] Added comments --- .../org/codedifferently/ExerciseType.java | 15 ++- .../java/org/codedifferently/FitnessApp.java | 120 ++++++++++++------ src/main/java/org/codedifferently/Person.java | 25 +++- 3 files changed, 116 insertions(+), 44 deletions(-) diff --git a/src/main/java/org/codedifferently/ExerciseType.java b/src/main/java/org/codedifferently/ExerciseType.java index 073a747..c5b233e 100644 --- a/src/main/java/org/codedifferently/ExerciseType.java +++ b/src/main/java/org/codedifferently/ExerciseType.java @@ -1,10 +1,23 @@ package org.codedifferently; +// Enum representing the different categories of exercises a workout can include public enum ExerciseType { + + // Exercises that target chest muscles CHEST, + + // Exercises that target back muscles BACK, + + // Exercises that target shoulder muscles SHOULDERS, + + // Exercises that target arm muscles ARMS, + + // Exercises focused on cardiovascular endurance CARDIO, + + // Exercises that target leg muscles LEGS -} +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/FitnessApp.java b/src/main/java/org/codedifferently/FitnessApp.java index 9171378..109bc5b 100644 --- a/src/main/java/org/codedifferently/FitnessApp.java +++ b/src/main/java/org/codedifferently/FitnessApp.java @@ -1,25 +1,29 @@ package org.codedifferently; + import java.util.ArrayList; import java.util.Date; import java.util.Scanner; +// Manages the main workflow of the LiftLogic fitness application public class FitnessApp { + + // Stores all registered users in the system private static ArrayList users = new ArrayList<>(); + + // Starts the application and displays the main menu public static void startApp(Scanner sc) { System.out.println("Welcome to LiftLogic!"); int input; - // Stores appointment data for generating a journal upon exit. - do { - // Displays the main menu options to the user. + // Displays main menu options System.out.println("\n=== LiftLogic ==="); System.out.println("1) Signup"); System.out.println("2) Login"); System.out.println("0) Quit"); System.out.print("Choose: "); - // Validates numeric input before processing. + // Validates numeric menu input if (sc.hasNextInt()) { input = sc.nextInt(); } else { @@ -28,11 +32,13 @@ public static void startApp(Scanner sc) { sc.nextLine(); switch (input) { - // Handles the creation and storage of a new customer. + + // Creates a new user account case 1: signup(sc); break; - // Displays the full list of registered customers. + + // Attempts user login case 2: Person toLogin = validateLogin(sc); if (toLogin != null) { @@ -41,34 +47,41 @@ public static void startApp(Scanner sc) { System.out.println("Invalid username or password. Try again."); } break; - // Exits the system and prints a journal of completed appointments. + + // Exits the application case 0: System.out.println("\nExiting system..."); break; - // Handles invalid menu selections. + + // Handles invalid selections default: System.out.println("\nPlease select a valid option."); } - // Stopping condition. Program will exit when the user inputs 0. + } while (input != 0); } + // Registers a new user and logs them in private static void signup(Scanner sc) { String name = validateName(sc); String email = validateEmail(sc); System.out.print("Enter a password: "); String password = sc.nextLine(); + Person user = new Person(name, email, password); users.add(user); + + // Logs the new user into the system FitnessApp.login(user, sc); } + // Displays the logged-in user menu public static void login(Person person, Scanner sc) { System.out.println("Welcome, " + person.getName() + "!"); int input; do { - // Displays the main menu options to the user. + // Displays user dashboard menu System.out.println("\n=== LiftLogic ==="); System.out.println("1) Log a workout"); System.out.println("2) Display Leaderboard"); @@ -76,7 +89,7 @@ public static void login(Person person, Scanner sc) { System.out.println("0) Logout"); System.out.print("Choose: "); - // Validates numeric input before processing. + // Validates numeric input if (sc.hasNextInt()) { input = sc.nextInt(); } else { @@ -85,7 +98,8 @@ public static void login(Person person, Scanner sc) { sc.nextLine(); switch (input) { - // Handles the creation and storage of a new customer. + + // Creates and stores a workout for the user case 1: Workout workout = createWorkout(sc); ArrayList workouts = person.getWorkouts(); @@ -93,34 +107,42 @@ public static void login(Person person, Scanner sc) { person.setWorkouts(workouts); person.setActiveWorkout(workout); break; - // Displays the full list of registered customers. + + // Displays leaderboard (feature placeholder) case 2: break; - // Exits the system and prints a journal of completed appointments. + + // Opens user settings case 3: displaySettings(person, sc); break; + + // Logs the user out case 0: System.out.println("\nLogging out..."); break; - // Handles invalid menu selections. + + // Handles invalid selections default: System.out.println("\nPlease select a valid option."); } - // Stopping condition. Program will exit when the user inputs 0. + } while (input != 0); } + // Displays and processes user settings public static void displaySettings(Person person, Scanner sc) { int input; + do { + // Displays settings menu System.out.println("\n=== Settings ==="); System.out.println("1) Change Name"); System.out.println("2) Reset Password"); System.out.println("0) Exit"); System.out.print("Choose: "); - // Validates numeric input before processing. + // Validates numeric input if (sc.hasNextInt()) { input = sc.nextInt(); } else { @@ -129,15 +151,18 @@ public static void displaySettings(Person person, Scanner sc) { sc.nextLine(); switch (input) { - // Handles the creation and storage of a new customer. + + // Updates the user's name case 1: String name = validateName(sc); person.setName(name); break; - // Displays the full list of registered customers. + + // Updates the user's password after verification case 2: System.out.print("Enter your current password: "); String password = sc.nextLine(); + if (person.getPassword().equals(password)) { System.out.print("Enter your new password: "); String pass1 = sc.nextLine(); @@ -152,69 +177,78 @@ public static void displaySettings(Person person, Scanner sc) { } else { System.out.println("Invalid password."); } + break; + // Exits settings menu case 0: System.out.println("\nExiting settings..."); break; - // Handles invalid menu selections. + + // Handles invalid selections default: System.out.println("\nPlease select a valid option."); } - // Stopping condition. Program will exit when the user inputs 0. + } while (input != 0); } + // Creates a workout and collects exercise information public static Workout createWorkout(Scanner scanner) { + System.out.println("Create New Workout"); + // Collects workout duration System.out.print("Enter workout duration: "); String duration = scanner.nextLine(); + // Records workout date Date date = new Date(); + // Initializes workout object Workout workout = new Workout(duration, date, new ArrayList<>()); - // Ask how many exercises the workout contains + // Asks how many exercises to log System.out.print("How many exercises are in this workout? "); int exerciseCount = scanner.nextInt(); - scanner.nextLine(); // clear newline + scanner.nextLine(); for (int i = 0; i < exerciseCount; i++) { + // Collects exercise name System.out.println("\nExercise " + (i + 1)); - - // Ask for exercise name System.out.print("Enter exercise name: "); String name = scanner.nextLine(); - // Ask for calories burned + // Collects calories burned System.out.print("Enter calories burned: "); int calories = scanner.nextInt(); - scanner.nextLine(); // clear newline + scanner.nextLine(); - // Display enum exercise types + // Displays exercise type options System.out.println("Select Exercise Type:"); - ExerciseType[] types = ExerciseType.values(); for (int j = 0; j < types.length; j++) { System.out.println((j + 1) + ". " + types[j]); } + // Converts user selection to enum value int typeChoice = scanner.nextInt(); - scanner.nextLine(); // clear newline - + scanner.nextLine(); ExerciseType selectedType = types[typeChoice - 1]; + // Creates and adds exercise to workout Exercise exercise = new Exercise(selectedType, name, calories); - workout.addExercise(exercise); } + return workout; } - // Searches for a customer using their phone number and returns the match if found. + // Validates login credentials and returns the matching user public static Person validateLogin(Scanner sc) { + String email = validateEmail(sc); + System.out.print("Enter your password: "); String password = sc.nextLine(); @@ -223,34 +257,35 @@ public static Person validateLogin(Scanner sc) { return user; } } + return null; } - // Validates that the user's name input contains only permitted characters. + // Validates name input using a regex pattern public static String validateName(Scanner sc) { - // Repeats continuously until valid input is provided. + while (true) { - // Prompts the user to enter their name. + System.out.print("\nEnter a name: "); String name = sc.nextLine(); - // Checks whether the input matches the required name pattern. - // Allows letters and optionally single spaces, hyphens, or apostrophes between words. + // Checks name formatting rules if (name.matches("^[a-zA-Z]+([ '-][a-zA-Z]+)*$")) { - // Returns the validated name if it meets the pattern requirements. return name; } else { - // Displays an error message if validation fails. System.out.println("\nInvalid name. Please use letters only."); } } } + // Validates email format using regex public static String validateEmail(Scanner sc) { - // Prompts the user for a valid email address for the order. Will launch an error if it is invalid. + while (true) { + System.out.print("Enter your email address?: "); String email = sc.nextLine(); + try { if (!email.matches("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$")) { throw new IllegalArgumentException(); @@ -263,7 +298,8 @@ public static String validateEmail(Scanner sc) { } } + // Returns the list of registered users public static ArrayList getUsers() { return users; } -} +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/Person.java b/src/main/java/org/codedifferently/Person.java index bdf67f1..ed03d7b 100644 --- a/src/main/java/org/codedifferently/Person.java +++ b/src/main/java/org/codedifferently/Person.java @@ -1,13 +1,26 @@ package org.codedifferently; + import java.util.ArrayList; +// Represents a user of the fitness application public class Person { + + // Stores the person's name private String name; + + // Stores the person's email used for identification/login private String email; + + // Stores the person's password for authentication private String password; + + // Tracks the workout the user is currently performing (null if none) private Workout activeWorkout = null; + + // Stores all workouts associated with this user using a dynamic list private ArrayList workouts; + // Constructor initializes user information and an empty workout list public Person(String name, String email, String password) { this.name = name; this.email = email; @@ -15,43 +28,53 @@ public Person(String name, String email, String password) { this.workouts = new ArrayList<>(); } + // Returns the person's name public String getName() { return name; } + // Updates the person's name public void setName(String name) { this.name = name; } + // Returns the person's email public String getEmail() { return email; } + // Updates the person's email public void setEmail(String email) { this.email = email; } + // Returns the list of workouts associated with the user public ArrayList getWorkouts() { return workouts; } + // Replaces the user's workout list public void setWorkouts(ArrayList workouts) { this.workouts = workouts; } + // Returns the user's password public String getPassword() { return password; } + // Updates the user's password public void setPassword(String password) { this.password = password; } + // Returns the workout currently being performed public Workout getActiveWorkout() { return activeWorkout; } + // Sets the user's current active workout public void setActiveWorkout(Workout activeWorkout) { this.activeWorkout = activeWorkout; } -} +} \ No newline at end of file From f96910331fa99792f8ab8ea045a4c651fabbdd4e Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Fri, 6 Mar 2026 18:56:31 -0500 Subject: [PATCH 13/16] Feat: fixed password and add exercise bugs --- .../java/org/codedifferently/FitnessApp.java | 23 ++++++++++--------- .../java/org/codedifferently/Workout.java | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/codedifferently/FitnessApp.java b/src/main/java/org/codedifferently/FitnessApp.java index 9ef8690..acca00b 100644 --- a/src/main/java/org/codedifferently/FitnessApp.java +++ b/src/main/java/org/codedifferently/FitnessApp.java @@ -172,7 +172,7 @@ public static void displaySettings(Person person, Scanner sc) { String pass2 = sc.nextLine(); if (pass1.equals(pass2)) { - person.setPassword(password); + person.setPassword(pass1); } else { System.out.println("Passwords did not match."); } @@ -320,6 +320,16 @@ public static Person getMaxKey(Map map) { return maxPerson; } + public static int countExercises(Person person) { + int count = 0; + + for (Workout workout : person.getWorkouts()) { + count += workout.getExercises().size(); + } + + return count; + } + public static ArrayList buildLeaderboard(Map map) { ArrayList leaderboard = new ArrayList<>(); @@ -332,16 +342,6 @@ public static ArrayList buildLeaderboard(Map map) { return leaderboard; } - public static int countExercises(Person person) { - int count = 0; - - for (Workout workout : person.getWorkouts()) { - count += workout.getExercises().size(); - } - - return count; - } - public static void displayLeaderboard(ArrayList people) { Map map = new LinkedHashMap<>(); @@ -358,6 +358,7 @@ public static void displayLeaderboard(ArrayList people) { int rank = 1; for (Person person : leaderboard) { + System.out.println("****Leaderboard****"); System.out.println(rank + ". " + person.getName() + " completed " + map.get(person) + " exercises"); rank++; diff --git a/src/main/java/org/codedifferently/Workout.java b/src/main/java/org/codedifferently/Workout.java index b926be1..eb1a6ec 100644 --- a/src/main/java/org/codedifferently/Workout.java +++ b/src/main/java/org/codedifferently/Workout.java @@ -11,6 +11,7 @@ public class Workout { public Workout(String duration, Date date) { this.duration = duration; this.date = date; + exercises = new ArrayList<>(); } public String getDuration() { From a2b5a490f015eb340ac2ba3db8649fb6e5dda751 Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Fri, 6 Mar 2026 19:41:44 -0500 Subject: [PATCH 14/16] Feat: Added a case to display all workouts, removed date field, fixed all bugs --- .../java/org/codedifferently/Exercise.java | 29 ++++- .../java/org/codedifferently/FitnessApp.java | 120 ++++++++++++++++-- .../java/org/codedifferently/Workout.java | 46 ++++--- 3 files changed, 159 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/codedifferently/Exercise.java b/src/main/java/org/codedifferently/Exercise.java index 11e184d..55a6819 100644 --- a/src/main/java/org/codedifferently/Exercise.java +++ b/src/main/java/org/codedifferently/Exercise.java @@ -1,46 +1,61 @@ package org.codedifferently; +// Class that represents a single exercise public class Exercise { + + // The type of exercise (ex: cardio, strength, etc.) private ExerciseType type; + + // Name of the exercise (ex: Pushups, Running) private String name; + + // Number of calories burned during the exercise private int caloriesBurned; + // Constructor used to create a new Exercise object public Exercise(ExerciseType type, String name, int caloriesBurned) { - this.type = type; - this.name = name; - this.caloriesBurned = caloriesBurned; + this.type = type; // set exercise type + this.name = name; // set exercise name + this.caloriesBurned = caloriesBurned; // set calories burned } + // Returns the exercise type public ExerciseType getType() { return type; } + // Updates the exercise type public void setType(ExerciseType type) { this.type = type; } + // Returns the name of the exercise public String getName() { return name; } + // Updates the name of the exercise public void setName(String name) { this.name = name; } + // Returns the number of calories burned public int getCaloriesBurned() { return caloriesBurned; } + // Updates the number of calories burned public void setCaloriesBurned(int caloriesBurned) { this.caloriesBurned = caloriesBurned; } + // Displays the exercise information to the console public void displayExerciseInfo() { System.out.println("--------------------"); System.out.println("Exercise Information"); - System.out.println("Name: " + name); - System.out.println("Type: " + type); - System.out.println("Calories Burned: " + caloriesBurned); + System.out.println("Name: " + name); // print exercise name + System.out.println("Type: " + type); // print exercise type + System.out.println("Calories Burned: " + caloriesBurned); // print calories burned System.out.println(); } -} +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/FitnessApp.java b/src/main/java/org/codedifferently/FitnessApp.java index acca00b..fb5e1c1 100644 --- a/src/main/java/org/codedifferently/FitnessApp.java +++ b/src/main/java/org/codedifferently/FitnessApp.java @@ -70,6 +70,7 @@ private static void signup(Scanner sc) { System.out.print("Enter a password: "); String password = sc.nextLine(); + // Creates a new Person object and stores it in the users list Person user = new Person(name, email, password); users.add(user); @@ -88,6 +89,7 @@ public static void login(Person person, Scanner sc) { System.out.println("1) Log a workout"); System.out.println("2) Display Leaderboard"); System.out.println("3) Settings"); + System.out.println("4) Display all workouts"); System.out.println("0) Logout"); System.out.print("Choose: "); @@ -104,21 +106,31 @@ public static void login(Person person, Scanner sc) { // Creates and stores a workout for the user case 1: Workout workout = createWorkout(sc); + + // Adds workout to the user's workout list ArrayList workouts = person.getWorkouts(); workouts.add(workout); person.setWorkouts(workouts); + + // Marks this workout as the user's active workout person.setActiveWorkout(workout); break; - // Displays leaderboard (feature placeholder) + // Displays leaderboard rankings case 2: displayLeaderboard(getUsers()); break; - // Opens user settings + + // Opens user settings menu case 3: displaySettings(person, sc); break; + // Displays all workouts the user has done + case 4: + displayAllWorkouts(person); + break; + // Logs the user out case 0: System.out.println("\nLogging out..."); @@ -165,22 +177,28 @@ public static void displaySettings(Person person, Scanner sc) { System.out.print("Enter your current password: "); String password = sc.nextLine(); + // Confirms the current password matches if (person.getPassword().equals(password)) { + + // Prompts for new password twice System.out.print("Enter your new password: "); String pass1 = sc.nextLine(); System.out.print("Enter your new password again: "); String pass2 = sc.nextLine(); + // Ensures both new passwords match if (pass1.equals(pass2)) { person.setPassword(pass1); } else { System.out.println("Passwords did not match."); } + } else { System.out.println("Invalid password."); } break; - // Exits settings menu + + // Exits settings menu case 0: System.out.println("\nExiting settings..."); break; @@ -193,7 +211,7 @@ public static void displaySettings(Person person, Scanner sc) { } while (input != 0); } - // Creates a workout and collects exercise information + // Creates a workout and collects exercise information from the user public static Workout createWorkout(Scanner scanner) { System.out.println("Create New Workout"); @@ -202,17 +220,18 @@ public static Workout createWorkout(Scanner scanner) { System.out.print("Enter workout duration: "); String duration = scanner.nextLine(); - // Records workout date + // Records workout date automatically Date date = new Date(); // Initializes workout object - Workout workout = new Workout(duration, date); + Workout workout = new Workout(duration); // Asks how many exercises to log System.out.print("How many exercises are in this workout? "); int exerciseCount = scanner.nextInt(); scanner.nextLine(); + // Loops through and collects each exercise for (int i = 0; i < exerciseCount; i++) { // Collects exercise name @@ -249,17 +268,21 @@ public static Workout createWorkout(Scanner scanner) { // Validates login credentials and returns the matching user public static Person validateLogin(Scanner sc) { + // Requests email from user String email = validateEmail(sc); + // Requests password from user System.out.print("Enter your password: "); String password = sc.nextLine(); + // Searches through registered users for (Person user : FitnessApp.getUsers()) { if (user.getEmail().equals(email) && user.getPassword().equals(password)) { return user; } } + // Returns null if login fails return null; } @@ -289,11 +312,13 @@ public static String validateEmail(Scanner sc) { String email = sc.nextLine(); try { + // Validates email pattern if (!email.matches("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$")) { throw new IllegalArgumentException(); } else { return email; } + } catch (IllegalArgumentException e) { System.out.println("\nInvalid email address. Try again.\n"); } @@ -305,7 +330,20 @@ public static ArrayList getUsers() { return users; } + // Displays all the workouts the user has done + public static void displayAllWorkouts(Person person){ + // If there are no workouts completed display a message + if (person.getWorkouts().size() ==0){ + System.out.println("No workouts have been completed"); + } + + // Cycles through the list of workouts to display the data of each workout + for (Workout workout: person.getWorkouts()){ + workout.displayWorkoutInfo(); + } + } + // Finds the person with the highest value in the map public static Person getMaxKey(Map map) { int maxExercises = -1; Person maxPerson = null; @@ -320,6 +358,7 @@ public static Person getMaxKey(Map map) { return maxPerson; } + // Counts total number of exercises completed by a person public static int countExercises(Person person) { int count = 0; @@ -330,9 +369,27 @@ public static int countExercises(Person person) { return count; } + // Counts total calories burned by a person across all workouts + public static int countCaloriesBurned(Person person) { + int count = 0; + + // Retrieves the user's workouts + ArrayList workouts = person.getWorkouts(); + + for (Workout workout : workouts) { + for (Exercise exercise : workout.getExercises()) { + count += exercise.getCaloriesBurned(); + } + } + + return count; + } + + // Builds a sorted leaderboard from a map of people and scores public static ArrayList buildLeaderboard(Map map) { ArrayList leaderboard = new ArrayList<>(); + // Repeatedly finds the max value and removes it while (!map.isEmpty()) { Person maxPerson = getMaxKey(map); leaderboard.add(maxPerson); @@ -342,8 +399,10 @@ public static ArrayList buildLeaderboard(Map map) { return leaderboard; } - public static void displayLeaderboard(ArrayList people) { + // Displays leaderboard ranked by total number of exercises + public static void rankByTotalExercises(ArrayList people){ + // Stores people and their exercise totals Map map = new LinkedHashMap<>(); for (Person person : people) { @@ -351,17 +410,62 @@ public static void displayLeaderboard(ArrayList people) { map.put(person, totalExercises); } + // Copies map so original data is preserved Map copy = new LinkedHashMap<>(map); + // Builds sorted leaderboard ArrayList leaderboard = buildLeaderboard(copy); int rank = 1; + System.out.println("\n****Leaderboard****"); + System.out.println("Ranked by total amount of exercises: "); + + // Displays ranked results for (Person person : leaderboard) { - System.out.println("****Leaderboard****"); System.out.println(rank + ". " + person.getName() + " completed " + map.get(person) + " exercises"); rank++; } } + + // Displays leaderboard ranked by total calories burned + public static void rankByTotalCaloriesBurned(ArrayList people){ + + // Stores people and their calorie totals + Map map = new LinkedHashMap<>(); + + for (Person person : people) { + int totalCalories = countCaloriesBurned(person); + map.put(person, totalCalories); + } + + // Copies map so original data remains unchanged + Map copy = new LinkedHashMap<>(map); + + // Builds sorted leaderboard + ArrayList leaderboard = buildLeaderboard(copy); + + int rank = 1; + + System.out.println("\n****Leaderboard****"); + System.out.println("Ranked by total amount of calories burned: "); + + // Displays ranked results + for (Person person : leaderboard) { + System.out.println(rank + ". " + person.getName() + + " burned " + map.get(person) + " calories"); + rank++; + } + } + + // Displays both leaderboard rankings + public static void displayLeaderboard(ArrayList people) { + + // Shows ranking by total exercises + rankByTotalExercises(people); + + // Shows ranking by calories burned + rankByTotalCaloriesBurned(people); + } } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/Workout.java b/src/main/java/org/codedifferently/Workout.java index eb1a6ec..8e3e306 100644 --- a/src/main/java/org/codedifferently/Workout.java +++ b/src/main/java/org/codedifferently/Workout.java @@ -3,51 +3,55 @@ import java.util.ArrayList; import java.util.Date; +// Class that represents a workout session public class Workout { + + // How long the workout lasted (ex: "30 minutes") private String duration; - private Date date; + + // List that stores all exercises done in this workout private ArrayList exercises; - public Workout(String duration, Date date) { - this.duration = duration; - this.date = date; - exercises = new ArrayList<>(); + // Constructor used to create a new Workout object + public Workout(String duration) { + this.duration = duration; // set workout duration + exercises = new ArrayList<>(); // create an empty list of exercises } + // Returns the workout duration public String getDuration() { return duration; } + // Updates the workout duration public void setDuration(String duration) { this.duration = duration; } - public Date getDate() { - return date; - } - - public void setDate(Date date) { - this.date = date; - } - - + // Returns the list of exercises in this workout public ArrayList getExercises() { return exercises; } + // Adds a new exercise to the workout public void addExercise(Exercise exercise){ exercises.add(exercise); } + // Displays the workout information and all exercises in it public void displayWorkoutInfo(){ - System.out.println("******************************"); - System.out.println("\nWorkout Date " + date); - System.out.println("Duration: " + duration); - for (Exercise exercise : exercises) { - System.out.println(exercise); + System.out.println("******************************"); + + // Print workout duration + System.out.println("Duration: " + duration); + + // Loop through all exercises and print them + for (Exercise exercise : exercises) { + exercise.displayExerciseInfo(); } - System.out.println("******************************"); + + System.out.println("******************************"); } -} +} \ No newline at end of file From 018eada30c788890e614249d71183c31da5cef24 Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Mon, 9 Mar 2026 23:30:38 -0400 Subject: [PATCH 15/16] Feat: Added README.md to explain our Sprint Documentation --- src/main/java/org/codedifferently/README.md | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/org/codedifferently/README.md diff --git a/src/main/java/org/codedifferently/README.md b/src/main/java/org/codedifferently/README.md new file mode 100644 index 0000000..10b5b2f --- /dev/null +++ b/src/main/java/org/codedifferently/README.md @@ -0,0 +1,32 @@ +# Sprint Documentation + +## Sprint 1 — The Plan +Our project was originally designed to be a real-time workout tracking application that would allow users to track their exercises as they performed them. The goal was to help individuals monitor their workouts live, organize their routines, and keep track of their physical activity as it happened. +To support this functionality, we planned several core features. + +Users would be able to create workouts, add exercises to those workouts, and track their progress in real time. Exercises would be categorized using an enumeration to organize different types of workouts and improve the structure of the application. +The program was designed to include several main classes: FitnessApplication, Exercise, Person, and Workout. Each class represents a different part of the system, helping to organize user data, exercises, and workout sessions. Additionally, an ExerciseType enumeration was created to represent different categories of exercises. + +Work for this sprint was divided between both team members. Jayden implemented the Person class, FitnessApplication menu system and created the ExerciseType enumeration. Bryant implemented the Exercise, and Workout classes. + +## Sprint 2 - The Build +Sprint 2 — The Build + +During this sprint, we implemented the core structure of the fitness application. The program allows users to log workouts through a menu-based interface where they can create workout entries and associate exercises with them. Key classes such as FitnessApplication, Exercise, Person, and Workout were developed, along with the ExerciseType enumeration to categorize exercises. + +One major change from our original plan was shifting from a real-time workout tracker to a workout logging application. The initial concept required features like timers and more complex state management. Due to time constraints, we simplified the scope so users could log workouts after completing them rather than track them live. + +The main challenge was attempting to implement the more complex tracking functionality within the limited sprint timeframe. After recognizing that it would require significantly more time and testing, we adjusted the project scope and focused on building a reliable workout logger. + +By narrowing the scope, we were able to complete a functional application while still achieving the core goal of helping users organize and record workouts. This adjustment reflects a common reality in software development, where project plans often evolve to ensure a working product is delivered within constraints. + +## Sprint 3 — The Reflection +Several aspects of our program work well. The code is well organized and not overly complicated, with logic divided into multiple functions to keep responsibilities clear and manageable. The application also handles different types of user input without crashing, which helps maintain stability during use. + +With more time, we would improve the leaderboard system. Currently, it only ranks user progress in two ways, but we would expand it to include additional metrics to provide a more detailed view of user performance. + +The Java concepts we used most frequently were encapsulation, conditionals, and loops. Conditionals and loops were especially important for building the menu system and iterating through collections to manage workouts and exercises. + +One major takeaway from this project was the importance of coordination and communication when working in a team. Creating a clear plan before coding helped keep everyone aligned and reduced misunderstandings. We also learned that tools like diagrams are helpful for outlining the structure of a program before implementation. + +Overall, this experience helped us better understand both collaborative development and practical Java programming. \ No newline at end of file From 38282c67af761e47b764dceb8bef036c146be8d7 Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Mon, 9 Mar 2026 23:37:13 -0400 Subject: [PATCH 16/16] Fixed typo in the README --- src/main/java/org/codedifferently/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/codedifferently/README.md b/src/main/java/org/codedifferently/README.md index 10b5b2f..39bb9cc 100644 --- a/src/main/java/org/codedifferently/README.md +++ b/src/main/java/org/codedifferently/README.md @@ -10,7 +10,6 @@ The program was designed to include several main classes: FitnessApplication, Ex Work for this sprint was divided between both team members. Jayden implemented the Person class, FitnessApplication menu system and created the ExerciseType enumeration. Bryant implemented the Exercise, and Workout classes. ## Sprint 2 - The Build -Sprint 2 — The Build During this sprint, we implemented the core structure of the fitness application. The program allows users to log workouts through a menu-based interface where they can create workout entries and associate exercises with them. Key classes such as FitnessApplication, Exercise, Person, and Workout were developed, along with the ExerciseType enumeration to categorize exercises.