{"id":630,"date":"2024-11-20T05:02:50","date_gmt":"2024-11-20T05:02:50","guid":{"rendered":"https:\/\/farislabs.com\/?page_id=630"},"modified":"2024-11-21T04:40:09","modified_gmt":"2024-11-21T04:40:09","slug":"calorie-tracker-app","status":"publish","type":"page","link":"https:\/\/farislabs.com\/index.php\/calorie-tracker-app\/","title":{"rendered":"Calorie Tracker App"},"content":{"rendered":"\n<div class=\"wp-block-group has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\">\n<h1 class=\"wp-block-heading\">Calorie Tracker App<\/h1>\n\n\n\n<p class=\"has-text-align-center has-large-font-size\"><em>&#8220;A tool to monitor daily calorie intake and support dietary goals.&#8221;<\/em><\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-group has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\">\n<p>The <strong>Calorie Tracker App<\/strong> helps users track their daily calorie consumption and stay on top of their dietary goals. It provides an intuitive interface for logging food items, calculating total calories consumed, and notifying users when they exceed their daily calorie limit.<\/p>\n\n\n\n<p>This project demonstrates problem-solving through user-friendly design and efficient coding techniques.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-group has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\"><strong>Problem Statement<\/strong><\/h2>\n\n\n\n<p><strong>What Problem Does It Solve?<\/strong><br>Many individuals struggle to monitor their calorie intake, leading to challenges in maintaining a balanced diet or achieving health goals.<\/p>\n\n\n\n<p><strong>How Does It Solve It?<\/strong><br>The Calorie Tracker App allows users to log their meals, automatically tracks calories, and provides real-time feedback on their remaining calorie allowance for the day.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-group has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\"><strong>Key Features<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>User Registration<\/strong>\n<ul class=\"wp-block-list\">\n<li>Allows users to enter their name and weight.<\/li>\n\n\n\n<li>Automatically sets a personalized daily calorie limit based on user input.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Dynamic Menu System<\/strong>\n<ul class=\"wp-block-list\">\n<li>Provides options to log food, view stats, or exit.<\/li>\n\n\n\n<li>Handles invalid inputs gracefully with clear error messages.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Calorie Calculation<\/strong>\n<ul class=\"wp-block-list\">\n<li>Updates the remaining calorie allowance with each logged meal.<\/li>\n\n\n\n<li>Alerts users when they exceed their daily calorie limit.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Activity Suggestions<\/strong>\n<ul class=\"wp-block-list\">\n<li>When the user exceeds their calorie limit, the app suggests light or intense exercises to balance the extra intake.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/div>\n\n\n\n<div class=\"wp-block-group has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\"><strong>Workflow or User Scenarios<\/strong><\/h2>\n\n\n\n<p><strong>Scenario 1<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The user eats an apple (70 calories).<\/li>\n\n\n\n<li>They log the food into the app.<\/li>\n\n\n\n<li>The app subtracts 70 from their daily calorie limit (e.g., 2500 &#8211; 70 = 2430 remaining).<\/li>\n<\/ul>\n\n\n\n<p><strong>Scenario 2<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The user eats a sandwich (630 calories).<\/li>\n\n\n\n<li>The app updates the remaining calorie count to 1870.<\/li>\n<\/ul>\n\n\n\n<p><strong>Scenario 3<\/strong>:<\/p>\n\n\n\n<p>The app alerts them, calculates the excess, and suggests compensatory exercises.<\/p>\n\n\n\n<p>The user eats a sub (310 calories), exceeding their limit.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-group has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\"><strong>Code Implementation<\/strong><\/h2>\n\n\n\n<p>The code for the Calorie Tracker App focuses on user interaction, calorie tracking, and input validation. Key features include:<\/p>\n\n\n\n<p><strong>User Registration<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>System.out.print(\"Enter your name: \");\nuserName = scanner.nextLine();\nSystem.out.print(\"Enter your weight: \");\nuserWeight = scanner.nextInt();\ntotalCalorieLimit = calculateCalorieLimit(userWeight);\nremainingCalorieLimit = totalCalorieLimit;<\/code><\/pre>\n\n\n\n<p><strong>Dynamic Menu System<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>System.out.println(\"\\nMenu:\");\nSystem.out.println(\"1. Add food intake\");\nSystem.out.println(\"2. View daily intake stats\");\nSystem.out.println(\"3. Exit\");<\/code><\/pre>\n\n\n\n<p><strong>Calorie Tracking and Alerts<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (remainingCalorieLimit &lt; 0) {\n    exceededLimit = true;\n    System.out.println(\"You have exceeded your daily calorie limit!\");\n}<\/code><\/pre>\n<\/div>\n\n\n\n<div class=\"wp-block-group has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\"><strong>Challenges and Learnings<\/strong><\/h2>\n\n\n\n<p>During development, a key challenge was implementing robust input validation to handle unexpected or invalid user inputs. I learned how to use exception handling in Java to create a seamless user experience.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-group has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\"><strong>Future Improvements<\/strong><\/h2>\n\n\n\n<p><strong>Expanded Features<\/strong>: Add detailed nutritional breakdowns (e.g., protein, carbs, fats) for logged meals.<\/p>\n\n\n\n<p><strong>Persistent Storage<\/strong>: Save user data and calorie logs to a database for long-term tracking.<\/p>\n\n\n\n<p><strong>Mobile Interface<\/strong>: Create a mobile app version with a graphical interface for easier use.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-group has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>The Calorie Tracker App is a practical tool for anyone looking to monitor their diet effectively. By providing calorie calculations, real-time tracking, and actionable feedback, it helps users stay on track with their health goals while demonstrating efficient and user-focused coding practices.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-group has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\">\n<p>Below is the source code:<\/p>\n\n\n\n<pre class=\"wp-block-code alignwide\"><code>import java.util.InputMismatchException;\nimport java.util.Scanner;\n\npublic class Main {\n  \/\/ Stores the name of the user.\n  private static String userName;\n  \/\/ Stores the weight of the user.\n  private static int userWeight;\n  \/\/ Stores the total daily calorie limit, initialized to 0.\n  private static int totalCalorieLimit = 0;\n  \/\/ Stores the remaining daily calorie limit.\n  private static int remainingCalorieLimit;\n  \/\/ Tracks whether the user has exceeded the daily calorie limit.\n  private static boolean exceededLimit = false;\n\n  public static void main(String&#91;] args) {\n    Scanner scanner = new Scanner(System.in);\n\n    \/\/ Display welcome messages and instructions\n    System.out.println(\"Welcome to the Calorie Tracker App!\");\n    System.out.println(\"Please register to get started.\");\n\n    \/\/ Check if the user is registered\n    if (!isUserRegistered(scanner)) {\n      \/\/ If not registered, prompt the user to register\n      System.out.println(\"Please register to continue.\");\n      registerUser(scanner);\n    }\n\n    \/\/ Display the menu\n    while (true) {\n      System.out.println(\"\\nMenu:\");\n      System.out.println(\"1. Add food intake\");\n      System.out.println(\"2. View daily intake stats\");\n      System.out.println(\"3. Exit\");\n      try {\n        System.out.print(\"Enter your choice: \");\n        int choice = scanner.nextInt();\n        \/\/ Consume newline character\n        scanner.nextLine();\n        \/\/ Switch statement to handle user menu choice:\n        switch (choice) {\n          \/\/ - Case 1: Adds food intakes by calling the addFoodIntake() method.\n          case 1:\n            addFoodIntake(scanner);\n            break;\n          \/\/ - Case 2: Displays daily intakes statistics by calling the\n          \/\/ viewDailyIntakeStats() method.\n          case 2:\n            viewDailyIntakeStats();\n            break;\n          \/\/ - Case 3: Exits the program with a thank you message if the user chooses to\n          \/\/ exit.\n          case 3:\n            System.out.println(\"Thank you for using the Calorie Tracker App!\");\n            System.exit(0);\n            break;\n          \/\/ - Default: Prints an error message for invalid menu choices.\n          default:\n            System.out.println(\"Invalid choice. Please try again.\");\n        }\n      } catch (InputMismatchException e) {\n        System.out.println(\"Invalid choice. Please enter a number.\");\n        \/\/ Clear the scanner buffer\n        scanner.nextLine();\n      }\n    }\n  }\n\n  \/\/ Checks if the user is registered by verifying if the userName is not null and\n  \/\/ the userWeight is greater than 0.\n  private static boolean isUserRegistered(Scanner scanner) {\n    return userName != null &amp;&amp; userWeight &gt; 0;\n  }\n\n  \/\/ Registers the user by prompting them to enter their name and weight,\n  \/\/ calculates the calorie limit based on the weight, and stores the user's\n  \/\/ information.\n  private static void registerUser(Scanner scanner) {\n    System.out.print(\"Enter your name: \");\n    userName = scanner.nextLine();\n    System.out.print(\"Enter your weight (in lbs): \");\n    userWeight = scanner.nextInt();\n    scanner.nextLine(); \/\/ Consume newline character\n    calculateCalorieLimit();\n  }\n\n  private static void calculateCalorieLimit() {\n    \/\/ Calculate total daily calorie limit as 15 times the user's weight\n    totalCalorieLimit = userWeight * 15;\n    remainingCalorieLimit = totalCalorieLimit;\n  }\n\n  \/\/ Calculates the total daily calorie limit based on the user's weight.\n  private static void addFoodIntake(Scanner scanner) {\n    System.out.print(\"Enter the food you ate: \");\n    String food = scanner.nextLine();\n    System.out.print(\"Enter the number of calories in \" + food + \": \");\n    int calories = scanner.nextInt();\n    scanner.nextLine(); \/\/ Consume newline character\n\n    \/\/ Subtract user input calories from the remaining calorie limit\n    remainingCalorieLimit -= calories;\n\n    \/\/ Checks if the remaining calorie limit is negative, sets exceededLimit if\n    \/\/ true, and displays the excess calorie message.\n    if (remainingCalorieLimit &lt; 0) {\n      exceededLimit = true;\n      int excessCalories = Math.abs(remainingCalorieLimit);\n      System.out.println(\"You have exceeded your daily calorie limit by \" + excessCalories + \" calories.\");\n      System.out.println(\"Consider engaging in a light workout (e.g., walking) for approximately \"\n          + (excessCalories \/ 3) + \" minutes\");\n      System.out.println(\"or an intense workout (e.g., running or weight lifting) for approximately \"\n          + (excessCalories \/ 8) + \" minutes\");\n    }\n    \/\/ Displays the remaining calorie limit if it is not negative.\n    else {\n      System.out.println(\"Remaining calorie limit: \" + remainingCalorieLimit);\n    }\n  }\n\n  \/\/ Displays the daily intakes statistics, including the total and remaining\n  \/\/ calorie limits.\n  private static void viewDailyIntakeStats() {\n    System.out.println(\"Daily intake stats:\");\n    System.out.println(\"Total calorie limit: \" + totalCalorieLimit);\n    System.out.println(\"Remaining calorie limit: \" + remainingCalorieLimit);\n  }\n}<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Calorie Tracker App &#8220;A tool to monitor daily calorie intake and support dietary goals.&#8221; The Calorie Tracker App helps users track their daily calorie consumption and stay on top of their dietary goals. It provides an intuitive interface for logging food items, calculating total calories consumed, and notifying users when they exceed their daily calorie [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-630","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/farislabs.com\/index.php\/wp-json\/wp\/v2\/pages\/630","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/farislabs.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/farislabs.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/farislabs.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/farislabs.com\/index.php\/wp-json\/wp\/v2\/comments?post=630"}],"version-history":[{"count":4,"href":"https:\/\/farislabs.com\/index.php\/wp-json\/wp\/v2\/pages\/630\/revisions"}],"predecessor-version":[{"id":713,"href":"https:\/\/farislabs.com\/index.php\/wp-json\/wp\/v2\/pages\/630\/revisions\/713"}],"wp:attachment":[{"href":"https:\/\/farislabs.com\/index.php\/wp-json\/wp\/v2\/media?parent=630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}