Caffeine Absorption

3
Caffeine Absorption The Problem: To create a program that displays the half-life of caffeine in the human body, the amount of caffeine in the human body after 24 hours, and the amount of caffeine in the body if someone drinks a cup of coffee every hour for 24 hours. Developed Solution and User Interface: This highly simple program only has three display fields, and a single button (Fig 4.1). Fig 4.1 The first display field is used to display how long it takes 130 mg of caffeine to be reduced to half within the human body at a loss rate of 13%. The second field, displays the amount of caffeine, from one cup of coffee, left in the body after 24 hours at a loss rate of 13%. The last field displays how much caffeine will be in the body if someone drinks a cup of coffee every hour, for 24 hours. The Calculate button, once pressed, will calculate the information for each of the three display fields detailed above. Code The Application: Out of all four of the applications in this project, this one is the simplest. There are three loops that perform the needed calculations.

description

Programming Project

Transcript of Caffeine Absorption

Page 1: Caffeine Absorption

Caffeine AbsorptionThe Problem:

To create a program that displays the half-life of caffeine in the human body, the amount of caffeine in the human body after 24 hours, and the amount of caffeine in the body if someone drinks a cup of coffee every hour for 24 hours.

Developed Solution and User Interface:

This highly simple program only has three display fields, and a single button (Fig 4.1).

Fig 4.1

The first display field is used to display how long it takes 130 mg of caffeine to be reduced to half within the human body at a loss rate of 13%.

The second field, displays the amount of caffeine, from one cup of coffee, left in the body after 24 hours at a loss rate of 13%.

The last field displays how much caffeine will be in the body if someone drinks a cup of coffee every hour, for 24 hours.

The Calculate button, once pressed, will calculate the information for each of the three display fields detailed above.

Code The Application:

Out of all four of the applications in this project, this one is the simplest. There are three loops that perform the needed calculations.

Two of them are the same For loop that counts down from 24 hours, down to one hour.

The third loop, a Do…. Until loop, reduces the amount of caffeine by the loss rate every iteration until the caffeine equals, or becomes less than 65.

Page 2: Caffeine Absorption

Testing:

This program, once I tested it, functioned as expected, with no problems.

Documentation:

Once you start up the application, you will be presented with this window:

The program calculates the amount of caffeine in the body for three different cases:

> How long it takes a single cups worth of caffeine to be reduced to half its starting amount.> The amount of caffeine remaining for one cup of coffee after 24 hours.> The amount of caffeine in your system should you drink a cup of coffee every hour for 24 straight hours.

To see these calculations, simply press the “Calculate Values” button, and the text fields to the right will be populated with the results (Fig 4.2).

Fig 4.2