|
Lars P. Linden MIS Dept. University of Central Florida |
Lab 05
Decision Structures
About This Lab
Create an application that, given inputs, makes decisions about whether a company is "green" or not.
Why do this application?
- covers If Then statements
- covers IsNumeric() function
- covers Boolean data type
- covers compound conditional
Use this to start the application: Decision_Structures_starter [zip]
Review of the Interface
The interface has several controls to allow the input of data and one button to trigger the decision process.

Decision #1: Is the organization carbon neutral?
Technique: Use an If statement.
For this application, a company is considered "carbon neutral" if they purchase a value of carbon offsets greater than or equal to the estimated cost of their carbon-dioxide emissions.

Get the Text of the cost of carbon-dioxide emissions and store the value in a variable.
Get the Text of the carbon offsets purchased from a carbon credit exchange and store the value in a variable.
Note that if you test this application and enter a non-numerical amount in one of these TextBoxes, the system will crash.
We solve this problem with an If statement and the IsNuman eric() function.
Below is the re-written code:
Next, we need to consider the decision.
We want to use our intermediate result later in the overall "Green" assessment decision, so we will save it in a variable.
We want to save a True or a False, so create a Boolean variable.
Now, code an If Then statement, to make the "Carbon Neutral" decision.
Assign True or False to this variable depending upon the result of the above decision. Once set, this variable will be used to during the overall "green" assessment.
Display an error message in the "lblStatusMessage" Label.
Decision #2:
Technique: Use several If statements.
The "Green Washing" section of the application looks like this:

Here is how it works!
The organization earns points, so declare a variable to store the value that is being calculated.
Your programming task is to use If statements for each of these controls to add or subtract the respective points.
For each CheckBox the organization earns 1 point.
However, the company loses points for unsubstantiated green advertising (saying that they are green when they really aren't). See the ComboBox for these numbers.
Finally, we need to display the final "Green Washing" score to the Label.
Decision #3: The overall "green" assessment
Here are the interface details for the first decision:
| Control | Purpose |
| Label | for output of a overall "green" assessment |
| Button | this control triggers all decision (same as above) |
Technique: Use a compound conditional.
Use the Boolean variable that contain the results from the first decisions and the "Green Washing" score.

If the organization is Carbon Neutral and has a positive "Green Washing" score, then the overall "green" assessment of the company is "Yes". Otherwise, "No".
Assign the results label accordingly.
All done!
<< back to course home
Fall 2009

