Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Start by reading over the starter code that weve given you. Make sure that you understand it. Complete the assignment statements in the main method

Start by reading over the starter code that weve given you. Make sure that you understand it.

Complete the assignment statements in the main method for the variables currentSugar, targetSugar, carbEquiv, carbConsume and exercise. At the moment, each of these assignment statements assigns the number 0. For example, here is the first of the three assignments:

int currentSugar = 0; 

You should replace the 0 in each of the assignment statements with a call to a Scannermethod that reads an integer entered by the user from the keyboard.

Important: You must use the Scanner object created at the start of the main method, and you may not create an additional Scanner object.

You may assume that all of the values entered by the user are valid values, and thus you do not need to perform any checking for problematic values.

Complete the main method so that it uses the values of the variables to compute the correct dosage of insulin, using the following formula:

 :::text currentSugar - targetSugar carbConsume dosage = -------------------------- + ----------- - exercise 55 carbEquiv 

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 

Notes:

The formula that we have given you uses standard mathematical notation. You will need to use the appropriate Java operators and appropriate numeric literals in your code.

You may find it helpful to compute the cost in stages by first computing some of the components of the formula storing their values in one or more variables that you declare and then combining those components to compute the final result.

In the example above, the dosage happens to be an integer, but that wont always be the case, and you should make your computation as precise as possible. This means that you will need to be careful with the type that you select for your dosage variable (and any other variables that you may use for intermediate results) and in the expressions that you construct for your computations.

Display the appropriate message, which depends on the value of the computed dosage as follows:

If the computed dosage is exactly 1.0, the program should print the following message:

recommended dosage: 1 unit 

Note that the dosage is printed without a decimal, and that the final word printed is unit, not units.

If the computed dosage is greater than 0.0 and is a whole number other than 1.0, the program should still print the dosage without a decimal, but the final word should be units with an s at the end. For example, if the computed dosage is 6.0, the program should print:

recommended dosage: 6 units 

If the computed dosage is greater than 0.0 and is not a whole number (i.e., it has a fractional part), the program should print the full computed value, including all of the digits after the decimal point. For example, if the computed dosage is 7.125, the program should print:

recommended dosage: 7.125 units 

If the dosage is less than or equal to 0.0, the program should print the following message:

recommended dosage: 0 units 

Notes:

There is more than one way to test if the computed dosage is a whole number. You may want to consider using a type cast in some way.

Make sure that the format of your results matches the examples that we have shown above.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems 12th Asian Conference ACIIDS 2020 Phuket Thailand March 23 26 2020 Proceedings

Authors: Pawel Sitek ,Marcin Pietranik ,Marek Krotkiewicz ,Chutimet Srinilta

1st Edition

9811533792, 978-9811533792

More Books

Students also viewed these Databases questions

Question

Describe the function of a citator in the tax research process.

Answered: 1 week ago

Question

Describe the types of power that effective leaders employ

Answered: 1 week ago

Question

Describe how leadership styles should be adapted to the situation

Answered: 1 week ago