Home

Healthier Developer Guide

Group CS2113-F10-2
Last update on 12 Apr 2021


Table of Contents


Getting Started

  1. Fork this repo to your GitHub account
  2. Clone the forked repo into your machine
  3. Ensure you have Java SE 11 installed
  4. Import the repo in your Java IDE as project
  5. Start hacking!

💡 You are advised to choose JetBrain’s Intellij IDEA as your IDE.

Get back to Table of Contents


Design

This section describes design details of the app Healthier.

Architecture

architecture

Figure 1: Architecture Diagram

The high-level design of Healthier is shown in Figure 1: Architecture Diagram given above.

Healthier corresponds to the main class that coordinates the execution of this application. It is where the main method is located. It is responsible for,

Common contains classes that can be repeatedly used by other components.

In addition to that, the app also consists of following components:

đź’ˇHealthier is an application that runs locally without Internet connections.
Data files will be stored in the format of plain-text documents for easy inspection and test.

Each of the components has corresponding Java classes that

More information about the components will be discussed in the Components section.

The interactions between major components

We will take how Healthier handles user’s input as an representative example to illustrate the internal logic of this application.

The Sequence Diagram of the operation is given below: Sequence diagram of handling user input

Figure 2: Sequence Diagram of handling user input

After initialization, Healthier calls the loopCommand() method, which gets user input in a while loop which terminates only when the command is exit, i.e. "exit" is received.
Inside the loop, UI will handle the read of user input, and pass the raw input in String to CommandParser, where the input will be validated and a corresponding instance of Command will be created.
After that, the execute command will be invoked and the returned result in String will be printed by UI. At the end of the loop, the store() method of Storage will be called to update the local files to reflect any changes, and the parsed parameters in CommandParser will be cleared to get ready for next parse.

Components

UI component

API: UI.java

Parser component

API: CommandParser.java

Entity component

APIs: Goal.java,Record.java,GoalList.java, RecordList.java, etc

Structure of the Entity Classes

Figure 3: class structure for entity classes

Command component

APIs: Command.java, CommandResult.java, etc

Structure of the Commands

Figure 4: class structure for Command

How the command is executed?

  1. UI component takes in user’s input, which is then passed to Parser component.
  2. Parser component processes the user input and create a Command object initialized with relevant parameters.
  3. The Command object is returned to Healthier, in which the execute method is invoked.
  4. The execute method returns the execution result in String, which is displayed by UI.

Storage component

APIs: Storage.java, FileInfoReader.java, FileInfoWriter.java

Structure of the Storage

Figure 5: class structure for entity classes

Common component

API: messages.java

Get back to Table of Contents


Implementation

This section describes details of how some of the important features are implemented, which can give some insights about how features are realized in general.

Add record feature

Adding a record to record list is achieved by AddCommand and RecordList. Records of the same category are stored as a RecordList. A ReocrdList supports the following operation:

All Record in a RecordList are of the same type so each user has 4 RecordList to hold EXERCISE, DIET , BODY_WEIGHT, SLEEP records respectively.

FitCenter is a uniform interface to manipulate all the RecordList and provide interface FitCenter#addRecordToList(CommandRecordType type, Record record)

Given below is an example of interaction among classes to add a new exercise record:

Step 1. The user enters a valid add command. An AddCommand will be initialized with the parsed parameters from user input.

Step 2. The AddCommand initializes a Record and calls FitCenter#FitCenter#addRecordToList(CommandRecordType type, Record record) to add the record.

đź’ˇ If any of the parameters passed are invalid, AddCommand will throw an error and will not call FitCenter#FitCenter#addRecordToList(CommandRecordType type, Record record), so the record will not be saved into the RecordList.

Step 3.FitCenter#FitCenter#addRecordToList(CommandRecordType type, Record record) calls RecordList#addRecord(Record newRecord) to modify the list.

The following sequence diagram shows how the add command works:

Sequence diagram of adding a new record

Figure 6: Sequence Diagram of adding a record

Get back to Table of Contents

Set Goal feature

The functionality of setting a goal and maintaining the goal in a goal list is achieved by SetCommand.
The realization is facilitated by FitCenter, as discussed previously in the Add record feature .
A goal has the following attributes: dateSet, intervalType, target, and progress.
As a goal corresponds to a kind of record, each goal object will also have a type attribute, which can be EXERCISE , DIET, SLEEP, and BODYWEIGHT.
Hence, once a goal object is created, it will be added to a GoalList in which more operations are defined and utilized by FitCenter, which contains the following method:

How the setting is done?

Take the example of setting a goal:

Step 1. The user enters a valid set command. A SetCommand instance will be initialized with parameters from user input parsed by CommandParser .

Step 2. The SetCommand initializes a Goal with parameters specified by the user, and the command object is returned to Healthier.

Step 3. The execute method of the SetCommand object is invoked, and it calls FitCenter#addGoalToList(CommandRecordType type, Goal goal) by passing the goal object of a particular record type, which adds the goal into the goal list.

Step 4. If the Goal object is not null, FitCenter#addGoalToList(CommandRecordType type, Goal goal) calls GoalList#addGoal(Goal newGoal) to update the list and the progress of the goal (if any).

The following Sequence Diagram illustrates how the set command works: Sequence Diagram of SetCommand

Figure 7: Sequence Diagram of Setting a Goal

Future Works

  1. Smart recommendation for food and workout.
  2. Multi-user capability with file separation & encryption.
  3. Friend/leaderboard features that encourages user to compete.
  4. Some other health indicators for monitoring, such as height and blood pressure.
  5. Graphical user interface.

Appendix: Requirements

Product Scope

Target User Profile

Value proposition

Get back to Table of Contents

User Stories

Version As a … I want to … So that I can …
v1.0 new user see usage instructions refer to them when I forget how to use the application
v1.0 user upload/delete my workout exercise/duration data keep track of my exercise history daily
v1.0 user upload/delete my diet details keep track of the food I eat daily
v1.0 user upload/delete my sleeping data keep track of my sleeping hours daily
v1.0 user upload/delete my body weight keep track of my body weight daily
v1.0 user view my history workout exercise/duration data know the progress of my strength
v1.0 user view my diet details know my daily/weekly calorie intake
v1.0 user view my history sleeping data see my past sleeping hours daily/weekly
v1.0 user view my history body weight data monitor the weight change
v2.0 user set goals for exercises have a reference and try to reach my exercise goals
v2.0 user set goals for diet have a reference and try to reach my diet goals
v2.0 user set goals for body weight have a reference and try to reach my exercise goals
v2.0 user set goals for sleeping hours have a reference and try to reach my weight goals
v2.0 user check existing goals set view the list of achieved goals and know the progress of unachieved goals
v2.0 user cancel a goal set previously stop tracking a goal that I am no longer interested in achieving
v2.1 user use the app without encountering bugs ensure my data are correctly recorded

Non-Functional Requirements

Get back to Table of Contents


Glossary

Get back to Table of Contents


Instructions for manual testing

Given below are instructions to test the app manually.

Note: The instructions serve as a starting point for test, only basic test cases are listed for reference.

Launch and shutdown

  1. Initial launch

    1. Download the jar file and copy into an empty folder

    2. Execute the jar file in command line window by command java -jar tp.jar.

  2. Use command exit to terminate the application/

Adding a record

  1. Adding an exercise record
    1. Test case: add t/E a/walking d/40
      Expected: A record of walking for 40 minutes on the current system date is added.

    2. Test case: add t/E a/abc d/40
      Expected: An error message is displayed since “abc” is not a valid workout type.

    3. Test case: add t/E a/running d/40 date/10-04-2021
      Expected: A record of walking for 40 minutes on 10/04/2021 is added.

  2. Adding a diet record
    1. Test case: add t/D f/fruit w/50
      Expected: A record of having 50g fruit on the current system date is added.

    2. Test case: add t/D f/fruit w/abc
      Expected: An error message is displayed since “abc” is not a food amount value.

    3. Test case: add t/D f/fruit w/50 date/10-04-2021
      Expected: A record of having 50g fruit on 10/04/2021 is added.

  3. Adding a sleep record
    1. Test case: add t/S d/8
      Expected: A record of sleeping for 8 hours on the current system date is added.

    2. Test case: add t/S
      Expected: An error message is displayed since the syntax for add command is invalid.

    3. Test case: add t/S d/8 date/10-04-2021
      Expected: A record of sleeping for 8 hours on 10/04/2021 is added.

  4. Adding a sleep record
    1. Test case: add t/W w/68
      Expected: A record for body weight of 68.0kg on the current system date is added.

    2. Test case: add t/W w/abc
      Expected: An error message is displayed since “abc” is not a valid value for body weight.

    3. Test case: add t/W w/68 date/10-04-2021
      Expected: A record for body weight of 68.0kg on 10/04/2021 is added.

View record lists

  1. View exercise records
    1. Test case: view t/E
      Expected: All exercise records are displayed.

    2. Test case: view t/E a/running
      Expected: All exercise records of running are displayed.

  2. View diet records
    1. Test case: view t/D
      Expected: All diet records are displayed.

    2. Test case: view t/E f/abc
      Expected: An error message is displayed since “abc” is not a valid food type.

  3. View sleep records
    1. Test case: view t/S
      Expected: All sleep records are displayed.

    2. Test case: view t/S date/10-04-2021
      Expected: All sleep records on date 10/04/2021 are displayed.

  4. View body weight records
    1. Test case: view t/W
      Expected: All body weight records are displayed.

    2. Test case: view t/W date/2021-04-10
      Expected: An error message is displayed since the date is not in the supported format.

Delete a record

  1. Delete a record of specific type

    1. Prerequisites: List all records using view command.

    2. Test case: delete t/E i/1
      Expected: First exercise record is deleted from the list.

    3. Test case: delete t/D i/0
      Expected: An error message is displayed since 0 is out of valid range of record index.

    4. Test case: delete t/S i/2
      Precondition: The sleep record list has at least 2 records.
      Expected: The second sleep record is deleted from the list.

    5. Test case: delete t/W
      Expected: An error message is displayed since the syntax for delete command is invalid.

Setting a goal

  1. Setting an exercise goal
    1. Test case: set t/E p/D target/300
      Expected: A goal of taking exercises to burn 300Kcal every day is set.

    2. Test case: set t/E p/W target/3000
      Expected: A goal of taking exercises to burn 3000Kcal every week is set.

  2. Setting a diet goal
    1. Test case: set t/D p/D target/1500
      Expected: A goal of taking in 1500Kcal every day is set.

    2. Test case: set t/D p/W target/abc
      Expected: An error message is displayed since “abc” is not a valid value for target calorie input.

  3. Setting a sleep goal
    1. Test case: set t/S p/D target/8
      Expected: A goal of sleeping 8 hours every day is set.

    2. Test case: set t/S p/A target/8
      Expected: An error message is displayed since “A” is not a valid goal type.

  4. Setting a body weight goal
    1. Test case: set t/W p/W target/60
      Expected: A weekly goal of reaching the body weight of 60kg is set.

    2. Test case: set t/W p/W target/abc
      Expected: An error message is displayed since “abc” is not a valid body weight target value.

Checking progress of goals

  1. Checking progress of goals of a specific type.

    1. Test case: check t/E
      Expected: Progress of all exercise goals are displayed.

    2. Test case: check t/D p/D
      Expected: Progress of all daily diet goals are displayed.

    3. Test case: check t/S p/W
      Expected: Progress of all weekly sleep goals are displayed.

    4. Test case: check t/W
      Expected: Progress of all body weight goals are displayed.

    5. Test case: check t/W p/a
      Expected: An error message is displayed since “a” is not a valid goal type.

Canceling a goal

  1. Delete a record of specific type

    1. Prerequisites: check the list of all goals using check command.

    2. Test case: cancel t/E i/1
      Expected: First exercise goal is cancelled and removed from the list.

    3. Test case: cancel t/D i/0
      Expected: An error message is displayed since 0 is out of valid range of goal index.

    4. Test case: cancel t/S i/2
      Precondition: The sleep goal list has at least 2 goals.
      Expected: The second sleep goal is cancelled and removed from the list.

    5. Test case: cancel t/W
      Expected: An error message is displayed since the syntax for cancel command is invalid.

Get back to Table of Contents
Home