Table of Contents
A simple knowledge based system using Fuzzy Logic to provide weight-loss guide consist of a diet plan and a workout plan based on user's current state.
Warning: The diagnosis of body fatness and the weight-loss plan generated by this application is just imitation for programming purpose. You should not follow them. To get the right instructions, you should use actual weight-loss applications, or better yet, go to the doctor.
Before cloning and using this application, you'll need to install these things on your computer:
- Java SE Development Kit 17: Of course you need to have Java installed to run a Java application. I used Java 17, but I think it works fine with the widely-used Java 8 (JDK 1.8), as well.
- Apache NetBeans: a free, open source, integrated development environment (IDE) that enables you to develop desktop, mobile and web applications. The IDE supports application development in various languages, including Java, HTML5, PHP and C++. The IDE provides integrated support for the complete development cycle, from project creation through debugging, profiling and deployment. The IDE runs on Windows, Linux, Mac OS X, and other UNIX-based systems.
- Apache Tomcat 8.5: an open-source Java servlet container that implements many Java Enterprise Specs such as the Websites API, Java-Server Pages and last but not least, the Java Servlet.
- MySQL 8.0: an open source relational database management system that was originally released in 1995. MySQL is popular among all databases, and is ranked as the 2nd most popular database, only slightly trailing Oracle Database. Among open source databases, MySQL is the most popular database in use today and known as one of the most reliable and performative databases out there.
You can install this application by cloning this repository into your current working directory:
git clone https://github.com/theEmperorofDaiViet/eat-and-fit.git
After cloning the repository, you can open the project by NetBeans.
Add necessary libraries to the project by right-clicking on the Libraries folder, select the Add JAR/Folder command, and navigate to /web/lib, then select all jar files inside it. I stored all the libraries needed for the project in this folder.
Open MySQL and create a database according to the scripts in *.sql files in /web/sql.
Open the DAO.java class in /src/java/eatandfit/dao and change the information about the datasource to fit your own settings.
Back to NetBeans and run the application. If this is the first time you use Tomcat, NetBeans may display a dialog asking you to choose a web server for the application. Click "Add" and refer to the directory where Tomcat installed.
Finally, if NetBeans asks for Tomcat authentication, open the tomcat-users.xml file in the /conf folder under the Tomcat directory to see the username and password. You can change them if you want.
After that, the application will run on port 8080 by default. A new tab in your browser will be opened automatically, showing the home page of the application.
- Get and validate user input
- Process input by Fuzzy Logic to determine user's current state
- Provide a weight-loss plan based on user's state:
- A diet plan consist of 3 different types of eating days per week: low, moderate and high carb
- A workout plan of cardio and gym
- A detailed page about each dish in the diet, consist of nutrition info visualized by an interactable pie chart, recipe and steps to cook
- A detailed page about each exercise in the workout plan, consist of a video guide, overview and detailed instructions
This is a simple animation to illustrate the features of the application. The colors is wrong because of the limit of the tool I used. You can see the actual colors in the video below
- First, from the home page, I click the "Bắt đầu" button to start.
- A form consist of two radio button is displayed for selecting sex. In this example, I pretend to be a woman.
- After submit the sex, another form is displayed for entering current height and weight (in centimeters and kilograms, respectively). I intend to provide wrong data to illustrate data validation:
- Leave the fields blank
- Enter an improper value
- Enter a negative number
- Enter non-numeric characters
- Then, I enter a height of 155 cm and a weight of 40 kg, which my Fuzzy Logic considers to be "underweight". The application display a message to advise me to gain weight, not to lose weight.
- I go back and enter a height of 155 cm and a weight of 50 kg, which my Fuzzy Logic considers to be "normal". The application display a message to advise me to maintain that healthy weight.
- I go back again and enter a height of 155 cm and a weight of 65 kg, which my Fuzzy Logic considers to be "pre-obese". The application display another form to ask me whether I am new to weight-loss or not. I choose to be a beginner.
- Finally, a detailed weight-loss plan is displayed, consisting of:
- A diet plan with three menus for low, moderate, and high carb eating days. Each menu consists of nutrition info; a pie chart represent the percentage of calories from carbs, fat and protein; and dish for each meal. If I click on a dish, a detailed page for that dish is displayed. I can see the dish's image, it's nutrition info, recipe and steps to cook.
- A workout plan of cardio and gym. If I click on an exercise, a detailed page for that exercise is display. It provides an video guide, overview and specific instructions to do the exercise.
And this short video, which converted to gif, will show the effect that can't be presented by the animation above:
- Now you can see the actual colors of the website, it's brighter than the colors in the animation.
- You can interact with the pie chart by holding the mouse on each slice to see it's details; or click to explode it.
- The slice represents carbs is exploded by default to emphasize the percent calories from carbs, which determine the diet is low, moderate, or high carb.
- Look at the lay out and colors of the chart, does it look like the website's logo, huh?
- The exercise video guide from Muscle & Strength is very good, right?
I want to say a big thanks to Eat This Much and Muscle & Strength. I used some of their knowledge in diet and workout to build this project, but I also adjusted these knowledge a bit to match my programming idea. So, again:
Warning: DO NOT trust in the plan in this application. You should go to Eat This Much and Muscle & Strength's website to see the RIGHT instructions.
You can contact me via: