GROUP WORK REPORT
CSC248
Fundamentals Of Data Structure
CLASS: CDCS1103B
LECTURER : DR MUHAMMAD FIRDAUS
MUSTAPHA
NAME MATRIX NUMBER
MUHAMMAD AMIRUL BIN MOHD HAMIZI 2023815146
MOHAMMAD MUZAMMIL BIN IBRAHIM 2023889766
NIK MUHAMMAD SYAFI FITRI BIN NIK 2023661508
MOHD YUSAIRI
SYAZRIL IZHAN BIN SHUHAIMI 2023664354
TABLE OF CONTENT
Introduction of Project 2
Complete coding of all classes 4
Class Node 3
Class LinkedList 4
Class Queue 5
Class User 6
Class HealthData 7
Class HealthApp 9
Sample input 19
Sample output 20
Introduction of Project
In today’s fast-paced world, maintaining health and wellness has become more
important than ever. With advancements in technology, healthcare systems have evolved to
provide innovative solutions that enable individuals to monitor and manage their health
efficiently. From wearable devices to mobile health applications, modern healthcare systems
empower users to track vital health metrics, set goals, and receive timely alerts, fostering a
proactive approach to well-being.
The proposed Healthcare and Wellness System aims to harness these advancements
by offering a robust platform for real-time health monitoring, personalized goal setting, and
comprehensive data analysis. Designed with scalability and user-friendliness in mind, the
system integrates cutting-edge data management techniques and modular components to
support multiple users and ensure seamless functionality.
By bridging the gap between technology and healthcare, this system aspires to not
only simplify health tracking but also promote healthier lifestyles, enabling users to make
informed decisions and take control of their overall well-being. Through features like
threshold-based alerts, trend analysis, and historical data logging, the system will serve as a
vital tool for proactive health management in an increasingly digital age
All processes
1. Create Linked List object name healthDataList and store user data into
healthDataList
2. Remove users from healthDataList and Edit data of users in healthDataList
3. Display the user data in userQueue
4. Input user data from a file and save user data into a file
5. Search user data by using the User ID
6. Adding healthData for each users and warning the user if the health data is too
low or high
7. Allows user to view their progress in method ViewProgressDashboard
8. Calculate and show all data alongside average for Daily, Weekly and Monthly report
9. Provides suggestions where the user should improve
10. A simple and interactive menu system
2
Complete coding of all classes
Class Node
class Node<T> {
T data;
Node<T> next;
public Node(T data) {
this.data = data;
this.next = null;
}
}
3
Class LinkedList
class LinkedListH<T> {
private Node<T> head, tail;
private int size;
public LinkedListH() {
this.head = this.tail = null;
this.size = 0;
}
public void add(T data) {
addLast(data);
}
public void addLast(T data) {
Node<T> newNode = new Node<>(data);
if (tail == null) {
head = tail = newNode;
} else {
tail.next = newNode;
tail = newNode;
}
size++;
}
public T removeFirst() {
if (head == null) throw new IllegalStateException("List is
empty");
T data = head.data;
head = head.next;
if (head == null) tail = null;
size--;
return data;
}
public T peekFirst() {
if (head == null) throw new IllegalStateException("List is
empty");
return head.data;
}
public boolean isEmpty() {
return size == 0;
}
public int size() {
return size;
}
public Node<T> getHead() {
return head;
}
}
4
Class Queue
class QueueH<T> {
private LinkedListH<T> list;
public QueueH() {
list = new LinkedListH<>();
}
public void enqueue(T data) {
list.add(data);
}
public T dequeue() {
if (list.isEmpty()) {
throw new IllegalStateException("Queue is empty");
}
return list.removeFirst();
}
public boolean isEmpty() {
return list.isEmpty();
}
public Node<T> getHead() {
return list.getHead();
}
}
5
Class User
class User {
String userID;
String name;
int age;
String gender;
Threshold threshold;
public User(String userID, String name, int age, String gender) {
this.userID = userID;
this.name = name;
this.age = age;
this.gender = gender;
this.threshold = null;
}
public void setThreshold(Threshold threshold) {
this.threshold = threshold;
}
public Threshold getThreshold() {
return this.threshold != null ? this.threshold : new Threshold();
}
public void displayInfo() {
System.out.println("User ID: " + userID);
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Gender: " + gender);
System.out.println("Thresholds: " + getThreshold());
}
}
6
Class HealthData
class HealthData {
String healthDataID;
int heartRate;
int stepCount;
double sleepHours;
double calorieIntake;
long timestamp;
public HealthData(String id, int heartRate, int stepCount, double sleepHours, double
calorieIntake, long timestamp) {
this.healthDataID = id;
this.heartRate = heartRate;
this.stepCount = stepCount;
this.sleepHours = sleepHours;
this.calorieIntake = calorieIntake;
this.timestamp = timestamp;
}
}
7
Class HealthData
class Threshold {
int maxHeartRate, minHeartRate, dailyStepGoal;
double maxCalories;
public Threshold() {
this.maxHeartRate = 100;
this.minHeartRate = 60;
this.dailyStepGoal = 10000;
this.maxCalories = 2500;
}
public Threshold(int maxHeartRate, int minHeartRate, int dailyStepGoal, double
maxCalories) {
this.maxHeartRate = maxHeartRate;
this.minHeartRate = minHeartRate;
this.dailyStepGoal = dailyStepGoal;
this.maxCalories = maxCalories;
}
@Override
public String toString() {
return "Max Heart Rate: " + maxHeartRate +
", Min Heart Rate: " + minHeartRate +
", Daily Step Goal: " + dailyStepGoal +
", Max Calories: " + maxCalories;
}
}
8
Class HealthApp
import java.util.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class HealthApp {
private static QueueH<User> userQueue = new QueueH<>();
private static LinkedListH<HealthData> healthDataList = new LinkedListH<>();
public static void main(String[] args) {
Menu(userQueue);
}
public static void Menu(QueueH<User> userQueue) {
Scanner scanner = new Scanner(System.in);
boolean running = true;
while (running) {
System.out.println("\nWelcome to the HealthApp Menu!");
System.out.println("1. Add Health Data");
System.out.println("2. User Management");
System.out.println("3. Progress Dashboard");
System.out.println("4. Exit");
System.out.print("Please choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
AddHealthData(userQueue);
break;
case 2:
UserManagementMenu(userQueue);
break;
case 3:
ViewProgressDashboard(userQueue);
break;
case 4:
running = false;
System.out.println("Exiting the application.");
break;
default:
System.out.println("Invalid choice, please try again.");
}
}
}
public static void UserInput(QueueH<User> userQueue) {
Scanner scanner = new Scanner(System.in);
System.out.println("\nHow would you 9
like to register users?");
public static void UserInput(QueueH<User> userQueue) {
Scanner scanner = new Scanner(System.in);
System.out.println("\nHow would you like to register users?");
System.out.println("1. Manual Entry");
System.out.println("2. Upload from File");
System.out.println("3. Save All Users to File");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
System.out.print("Enter User ID: ");
String userID = scanner.nextLine();
System.out.print("Enter Name: ");
String name = scanner.nextLine();
System.out.print("Enter Age: ");
int age = scanner.nextInt();
scanner.nextLine();
System.out.print("Enter Gender (Male/Female): ");
String gender = scanner.nextLine();
userQueue.enqueue(new User(userID, name, age, gender));
System.out.println("User successfully registered.");
break;
case 2:
System.out.print("Enter the file path: ");
String filePath = scanner.nextLine();
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
String line;
while ((line = reader.readLine()) != null) {
String[] details = line.split(",");
if (details.length == 4) {
String fileUserID = details[0].trim();
String fileName = details[1].trim();
int fileAge = Integer.parseInt(details[2].trim());
String fileGender = details[3].trim();
userQueue.enqueue(new User(fileUserID, fileName, fileAge, fileGender));
}
}
System.out.println("Users successfully uploaded from file.");
System.out.println("\nUsers loaded from file:");
for (Node<User> node = userQueue.getHead(); node != null; node =
node.next) {
System.out.println("User ID: " + node.data.userID + ", Name: " +
node.data.name);
}
} catch (IOException e) {
System.out.println("Error reading file: " + e.getMessage());
} 10
case 3:
System.out.print("Enter the file path to save: ");
String savePath = scanner.nextLine();
try (BufferedWriter writer = new BufferedWriter(new FileWriter(savePath))) {
QueueH<User> tempQueue = new QueueH<>();
while (!userQueue.isEmpty()) {
User user = userQueue.dequeue();
writer.write(user.userID + "," + user.name + "," + user.age + "," +
user.gender);
writer.newLine();
tempQueue.enqueue(user);
}
while (!tempQueue.isEmpty()) {
userQueue.enqueue(tempQueue.dequeue());
}
System.out.println("Users successfully saved to file.");
} catch (IOException e) {
System.out.println("Error writing to file: " + e.getMessage());
}
break;
default:
System.out.println("Invalid choice, returning to menu.");
}
}
public static void SearchUser(QueueH<User> userQueue) {
Scanner scanner = new Scanner(System.in);
System.out.print("\nEnter User ID to search: ");
String searchID = scanner.nextLine();
boolean found = false;
QueueH<User> tempQueue = new QueueH<>();
while (!userQueue.isEmpty()) {
User currentUser = userQueue.dequeue();
if (Objects.equals(currentUser.userID, searchID)) {
System.out.println("\nUser Found:");
currentUser.displayInfo();
found = true;
}
tempQueue.enqueue(currentUser);
}
while (!tempQueue.isEmpty()) {
userQueue.enqueue(tempQueue.dequeue());
}
if (!found) {
System.out.println("User with ID " + searchID + " not found.");
}
nextActionMenu(userQueue);
}
11
public static void AddHealthData(QueueH<User> userQueue) {
Scanner scanner = new Scanner(System.in);
System.out.print("\nEnter User ID to add health data for: ");
String userID = scanner.nextLine();
boolean userFound = false;
QueueH<User> tempQueue = new QueueH<>();
while (!userQueue.isEmpty()) {
User currentUser = userQueue.dequeue();
if (currentUser.userID.equals(userID)) {
userFound = true;
System.out.print("Enter Health Data ID: ");
String healthDataID = scanner.nextLine();
System.out.print("Enter Heart Rate: ");
int heartRate = scanner.nextInt();
System.out.print("Enter Step Count: ");
int stepCount = scanner.nextInt();
System.out.print("Enter Sleep Hours: ");
double sleepHours = scanner.nextDouble();
System.out.print("Enter Calorie Intake: ");
double calorieIntake = scanner.nextDouble();
scanner.nextLine();
System.out.print("Enter Timestamp (as long): ");
long timestamp = scanner.nextLong();
scanner.nextLine();
HealthData healthData = new HealthData(healthDataID, heartRate, stepCount,
sleepHours, calorieIntake, timestamp);
healthDataList.add(healthData);
Threshold userThreshold = currentUser.getThreshold();
if (userThreshold != null) {
if (heartRate < userThreshold.minHeartRate || heartRate >
userThreshold.maxHeartRate) {
System.out.println("Warning: Heart rate out of threshold range!");
}
if (stepCount < userThreshold.dailyStepGoal) {
System.out.println("Warning: Step count below daily goal!");
}
if (calorieIntake > userThreshold.maxCalories) {
System.out.println("Warning: Calorie intake exceeds maximum limit!");
}
}
System.out.println("Health data added successfully.");
}
tempQueue.enqueue(currentUser);
}
12
while (!tempQueue.isEmpty()) {
userQueue.enqueue(tempQueue.dequeue());
}
if (!userFound) {
System.out.println("User with ID " + userID + " not found.");
}
nextActionMenu(userQueue);
}
public static void ViewProgressDashboard(QueueH<User> userQueue) {
Scanner scanner = new Scanner(System.in);
System.out.print("\nEnter User ID to view progress: ");
String userID = scanner.nextLine();
boolean userFound = false;
QueueH<User> tempQueue = new QueueH<>();
while (!userQueue.isEmpty()) {
User currentUser = userQueue.dequeue();
if (currentUser.userID.equals(userID)) {
userFound = true;
System.out.println("\n=== Progress Dashboard for User ===");
System.out.println("User ID: " + currentUser.userID);
System.out.println("Name: " + currentUser.name);
System.out.println("Age: " + currentUser.age);
System.out.println("Gender: " + currentUser.gender);
DailySummary(currentUser);
WeeklySummary(currentUser);
MonthlySummary(currentUser);
Suggestions(currentUser);
}
tempQueue.enqueue(currentUser);
}
while (!tempQueue.isEmpty()) {
userQueue.enqueue(tempQueue.dequeue());
}
if (!userFound) {
System.out.println("User with ID " + userID + " not found.");
}
nextActionMenu(userQueue);
}
public static void DailySummary(User user) {
System.out.println("\n--- Daily Summary ---");
13
long currentDayStart = System.currentTimeMillis() - (System.currentTimeMillis() % (24
long currentDayStart = System.currentTimeMillis() - (System.currentTimeMillis() %
(24 * 60 * 60 * 1000));
double totalCalories = 0;
int totalSteps = 0;
int totalHeartRate = 0;
int count = 0;
for (Node<HealthData> node = healthDataList.getHead(); node != null; node =
node.next) {
HealthData data = node.data;
if (data.timestamp >= currentDayStart) {
totalCalories += data.calorieIntake;
totalSteps += data.stepCount;
totalHeartRate += data.heartRate;
count++;
}
}
if (count > 0) {
double avgHeartRate = totalHeartRate / (double) count;
System.out.println("Heart Rate: Average " + avgHeartRate + " bpm");
System.out.println("Steps: " + totalSteps + " (Daily Goal: " +
user.threshold.dailyStepGoal + ")");
System.out.println("Calories: " + totalCalories + " kcal (Max Limit: " +
user.threshold.maxCalories + ")");
} else {
System.out.println("No health data available for today.");
}
}
public static void WeeklySummary(User user) {
System.out.println("\n--- Weekly Summary ---");
long currentWeekStart = System.currentTimeMillis() - (7 * 24 * 60 * 60 * 1000);
double totalCalories = 0;
int totalSteps = 0;
int totalHeartRate = 0;
int count = 0;
int daysMetStepGoal = 0;
for (Node<HealthData> node = healthDataList.getHead(); node != null; node =
node.next) {
HealthData data = node.data;
if (data.timestamp >= currentWeekStart) {
totalCalories += data.calorieIntake;
totalSteps += data.stepCount;
totalHeartRate += data.heartRate;
count++;
if (data.stepCount >= user.threshold.dailyStepGoal) {
daysMetStepGoal++;
}
}
}
14
if (count > 0) {
double avgHeartRate = totalHeartRate / (double) count;
System.out.println("Heart Rate: Average " + avgHeartRate + " bpm");
System.out.println("Steps: " + totalSteps + " total (Met goal on " + daysMetStepGoal
+ " days)");
System.out.println("Calories: " + totalCalories + " kcal total");
} else {
System.out.println("No health data available for the week.");
}
}
public static void MonthlySummary(User user) {
System.out.println("\n--- Monthly Summary ---");
long currentMonthStart = System.currentTimeMillis() - (30 * 24 * 60 * 60 * 1000);
double totalCalories = 0;
int totalSteps = 0;
int totalHeartRate = 0;
int count = 0;
int daysThresholdViolations = 0;
for (Node<HealthData> node = healthDataList.getHead(); node != null; node =
node.next) {
HealthData data = node.data;
if (data.timestamp >= currentMonthStart) {
totalCalories += data.calorieIntake;
totalSteps += data.stepCount;
totalHeartRate += data.heartRate;
count++;
if (data.heartRate < user.threshold.minHeartRate || data.heartRate >
user.threshold.maxHeartRate) {
daysThresholdViolations++;
}
}
}
if (count > 0) {
double avgHeartRate = totalHeartRate / (double) count;
System.out.println("Heart Rate: Average " + avgHeartRate + " bpm");
System.out.println("Steps: " + totalSteps + " total");
System.out.println("Calories: " + totalCalories + " kcal total");
System.out.println("Threshold Violations: " + daysThresholdViolations + " days");
} else {
System.out.println("No health data available for the month.");
}
}
public static void Suggestions(User user) {
System.out.println("\n--- Suggestions ---");
long currentDayStart = System.currentTimeMillis() - (System.currentTimeMillis() % (24
* 60 * 60 * 1000));
double totalCalories = 0;
int totalSteps = 0;
int totalHeartRate = 0; 15
for (Node<HealthData> node = healthDataList.getHead(); node != null; node =
node.next) {
HealthData data = node.data;
if (data.timestamp >= currentDayStart) {
totalCalories += data.calorieIntake;
totalSteps += data.stepCount;
totalHeartRate += data.heartRate;
count++;
if (data.heartRate < user.threshold.minHeartRate || data.heartRate >
user.threshold.maxHeartRate) {
thresholdViolated = true;
}
}
}
if (totalSteps >= user.threshold.dailyStepGoal) {
System.out.println("- Great job! You've met your daily step goal of " +
user.threshold.dailyStepGoal + " steps.");
} else {
System.out.println("- Try to walk more to meet your daily step goal of " +
user.threshold.dailyStepGoal + " steps.");
}
if (totalCalories <= user.threshold.maxCalories) {
System.out.println("- Excellent! You're staying within your daily calorie limit of " +
user.threshold.maxCalories + " kcal.");
} else {
System.out.println("- Watch your calorie intake. You're exceeding your daily limit of "
+ user.threshold.maxCalories + " kcal.");
}
if (!thresholdViolated && count > 0) {
System.out.println("- Your heart rate is within the healthy range of " +
user.threshold.minHeartRate + " to " + user.threshold.maxHeartRate + " bpm.");
} else if (count > 0) {
System.out.println("- Keep an eye on your heart rate. It's been out of the healthy
range of " + user.threshold.minHeartRate + " to " + user.threshold.maxHeartRate + " bpm at
times.");
} else {
System.out.println("- No heart rate data available for today.");
}
}
public static void EditUser(QueueH<User> userQueue) {
Scanner scanner = new Scanner(System.in);
System.out.print("\nEnter User ID to edit: ");
String userID = scanner.nextLine();
boolean userFound = false;
QueueH<User> tempQueue = new QueueH<>();
while (!userQueue.isEmpty()) {
User currentUser = userQueue.dequeue();
if (currentUser.userID.equals(userID))
16 {
System.out.println("Editing user details for " + userID);
System.out.print("Enter new Name: ");
currentUser.name = scanner.nextLine();
System.out.print("Enter new Age: ");
currentUser.age = scanner.nextInt();
scanner.nextLine();
System.out.print("Enter new Gender (Male/Female): ");
currentUser.gender = scanner.nextLine();
System.out.println("User details updated successfully.");
}
tempQueue.enqueue(currentUser);
}
while (!tempQueue.isEmpty()) {
userQueue.enqueue(tempQueue.dequeue());
}
if (!userFound) {
System.out.println("User with ID " + userID + " not found.");
}
nextActionMenu(userQueue);
}
public static void UserManagementMenu(QueueH<User> userQueue) {
Scanner scanner = new Scanner(System.in);
boolean backToMain = false;
while (!backToMain) {
System.out.println("\n--- User Management ---");
System.out.println("1. Register New User");
System.out.println("2. Search for a User");
System.out.println("3. Edit or Delete a User");
System.out.println("4. Return to Main Menu");
System.out.print("Please choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
UserInput(userQueue);
break;
case 2:
SearchUser(userQueue);
break;
case 3:
EditUser(userQueue);
break;
case 4:
backToMain = true;
break;
17
default:
}
}
}
public static void nextActionMenu(QueueH<User> userQueue) {
Scanner scanner = new Scanner(System.in);
System.out.println("\nWhat would you like to do next?");
System.out.println("1. Go back to the Main Menu");
System.out.println("2. User Management");
System.out.println("3. Add Health Data");
System.out.println("4. Progress Dashboard");
System.out.println("5. Exit");
System.out.print("Please choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
Menu(userQueue);
break;
case 2:
UserManagementMenu(userQueue);
break;
case 3:
AddHealthData(userQueue);
break;
case 4:
ViewProgressDashboard(userQueue);
break;
case 5:
System.exit(0);
break;
default:
System.out.println("Invalid choice, returning to menu.");
nextActionMenu(userQueue);
}
}
}
18
Sample input
19
Sample output
Input User Data Manually
20
Input User data from file
21
Save user data to a file
22
Search for a user
23