Question: The x - axis is the grind size ( 1 represents the finest grind and 8 represents the coarsest grind ) . Note that the

The x-axis is the grind size (1 represents the finest grind and 8 represents the coarsest grind). Note that the dynamic brewing pressure ranges from 9.7(finest grind) to 7.6(coarsest grind). However, the brewing time ranges from 48 seconds (finest grind) to 11 seconds (coarsest grind). Based on this figure, the perfect grind setting is either 4 or 5, where the brewing time is between 25 and 30 seconds and the dynamic pressure is between 8.5 and 8.8 BAR.
To help your get start in Coral, your boss gives you a starter code with a basic skeleton of brewCoffee function. Note that you need to complete the brewCoffee function by writing equations that compute factor and bias values.
Function brewCoffee (integer grindSize) returns integer brewTime
integer sPressure
float dPressure
float bias
float factor
sPressure =10
dPressure =0
bias =0
factor =0
// Express the relationship between grindSize and dPressure as an equation. The equation should
// include sPressure, grindSize, and factor that helps express the relationship of smaller
// grindSize resulting in higher dPressure. Complete the equation below to compute factor as a function of grindSize.
//
// factor = func(grindSize).
//
// As an example, you could set func as grindSize/10.
factor = grindSize /10
// Obviously, this function doesn't work because when grindSize is 1,
// dPressure is also 1. The correct factor should result in the highest
// dPressure when grindSize is smallest. Modify the above equation to compute
// factor.
// Next, the function below calculate dPressure
dPressure = sPressure * factor
// Next, since the relationship between the dPressure and brewTime is not linear, we need to
// set up bias value as part of calculating brewTime. This can be done using
// if, elseif, and else statements. The idea here is to set the bias to a
// value based on dPressure. A higher dPressure should result in a higher bias.
// Ultimately, the brewTime is calculated by multiplying dPressure with bias
// as shown later in the program.
// Complete the code below to set the bias values based on dPressure values.
// Below is a starter code. Simply remove the comment (//) to execute the
// code. Replace (...) with code and numeric values. Note that you will likely need more cases
// of elseif and else than provided.
//
//if dPressure >9.3
// bias =...
//elseif dPressure >...
// bias =...
//...
//else
// bias =...
// calculating brewTime
brewTime = dPressure * bias
// output the results
Put grindSize to output
Put "
" to output
Put dPressure to output
Put "
" to output
Put brewTime to output
Put "
" to output
Function Main() returns nothing
integer grindSize
grindSize = Get next input
Put brewCoffee(grindSize) to output
You can test your program by entering the following grindSize values, one at a time, in the Input window: 1,2,3,4,5,6,7, and 8.
Your espresso simulator should be as close as possible to the real behavior shown in the figure above. Slight variations are acceptable as long as the perfect shots are still within the ranges of 8.4-9.0 BAR (dynamic pressure) and 25 to 30 seconds (brewing time). The maximum and minimum brewing times should be 50 seconds and 10 seconds, respectively. The maximum and minimum dynamic pressure should be 9.7 BAR and 7.0 BAR, respectively.
As the last step, you need to modify the Main function so that it can self-generate grindSize values. Currently, you need to enter the grindSize as an input for each run. Your task is to replace the line below with a for loop where the grindSize value is set automatically to iterate from 1 to 8.
grindSize = Get next input
The following line should also be part of the new for loop.
Put brewCoffee(grindSize) to output

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!