Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Some people with type I diabetes inject insulin before each meal in order to sta

ID: 3629412 • Letter: S

Question

Some people with type I diabetes inject insulin before each meal in order to stabilize their blood-sugar level. The amount of insulin that is required depends on several factors.
In the file ComputeInsulinDosage.java, we have given you the beginnings of a program for computing the amount of insulin that a person should inject before a meal. Our starter code does the following:

-reads the person's current blood-sugar level (specified to the nearest integer) from the keyboard and stores it a variable named currentSugar
-reads the person's target blood-sugar level (also specified to the nearest integer) and stores it in a variable named targetSugar.
-reads the person's carbohydrate equivalency (the number of grams of carbs that are equivalent to one unit of insulin, specified to the nearest number of grams) and stores it in a variable named carbEquiv.
-reads the number of carbohydrates that the person plans to consume during the meal (specified to the nearest number of grams) and stores it in a variable named carbConsume.
-reads an integer from 0 to 3 indicating the amount of exercise the person plans to perform after the meal (0 = none, 3 = heavy exercise) and stores it in a variable named exercise.
You do not need to understand how the program obtains the values of these variables. You simply need to complete the program so that it uses the values of the variables to compute and print the correct dosage of insulin, using the following formula:

currentSugar - targetSugar carbConsume
dosage = ------------------------------ + ------------------ - exercise
55 carbEquiv
(This formula comes from a posting by Neil Bason on MyDiabetesCentral.com.)

For example, assume that a person enters the following values:

current blood sugar: 210
target blood sugar: 100
carbohydrate equivalency: 10
carbohydrates to consume: 60
amount of exercise: 2
For this person, the program should perform the following computation:

(210 - 100) 60
dosage = --------- + ---- - 2
55 10

= 110
--- + 6 - 2
55

= 2 + 6 - 2
= 6
and it should output the required dosage using a message like the following:
You should consume 6.0 units of insulin before the meal.

Important notes:
For this example, the dosage happens to be an integer. However, this will not always be the case. See guideline d below for more detail. Also, you do not need to round the dosage; rather, you should print the full value that you obtain, including all of the digits after the decimal point.
If the dosage ends up being less than or equal to 0, you should instead print the following message:
You do not need to consume any insulin before the meal.
Use an if-else statement to determine which message to print. See our ChangeAdder4.java program for an example of using this type of construct.  complete the program by filling in the remainder of the main method.

Implementation guidelines and requirements:

For example, let's say that you wanted to print the product of the values in the int variables d and e. Instead of doing this:


ComputeInsulinDosage code:

import java.util.*;

public class ComputeInsulinDosage {
public static void main(String[] args) {
int currentSugar; // current blood sugar
int targetSugar; // target blood sugar
int carbEquiv; // the person's carb equivalency in grams
int carbConsume; // grams of carbs to be consumed
int exercise; // 0-3. 0 = no exercise, 3 = heavy exercise

// Read the values from the user.
Scanner console = new Scanner(System.in);
System.out.print("current blood sugar: ");
currentSugar = console.nextInt();
System.out.print("target blood sugar: ");
targetSugar = console.nextInt();
System.out.print("carbohydrate equivalency: ");
carbEquiv = console.nextInt();
System.out.print("carbohydrates to consume: ");
carbConsume = console.nextInt();
System.out.print("amount of exercise (0-3): ");
exercise = console.nextInt();

/*
* The lines above read the necessary values from the user
* and store them in the variables declared above.
* Fill in the rest of the program below, using those
* variables to compute and print the value mentioned
* in the assignment.
*/


}
}

Explanation / Answer

please rate - thanks

import java.util.*;

public class ComputeInsulinDosage {
public static void main(String[] args) {
int currentSugar; // current blood sugar
int targetSugar; // target blood sugar
int carbEquiv; // the person's carb equivalency in grams
int carbConsume; // grams of carbs to be consumed
int exercise; // 0-3. 0 = no exercise, 3 = heavy exercise
double dosage;
// Read the values from the user.
Scanner console = new Scanner(System.in);
System.out.print("current blood sugar: ");
currentSugar = console.nextInt();
System.out.print("target blood sugar: ");
targetSugar = console.nextInt();
System.out.print("carbohydrate equivalency: ");
carbEquiv = console.nextInt();
System.out.print("carbohydrates to consume: ");
carbConsume = console.nextInt();
System.out.print("amount of exercise (0-3): ");
exercise = console.nextInt();

/*
* The lines above read the necessary values from the user
* and store them in the variables declared above.
* Fill in the rest of the program below, using those
* variables to compute and print the value mentioned
* in the assignment.
*/

dosage=(currentSugar-targetSugar)/55.+(double)carbConsume/carbEquiv-exercise;
System.out.println("You should consume "+dosage+" units of insulin before the meal.");
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote