Description
In information systems, a program often needs to respond differently
in different circumstances. For example, a system monitoring blood
pressure would need to respond differently for low, normal, and high
blood pressures. Or, a course registration system would need to notify a
student if a class was full.
Such differentiated responses utilize if-then or case
statements within class methods. You implemented an example if-then
statement in Benchmark 3. You have already incorporated or will be
incorporating this decision-based logic into a class method in Benchmark
4. Many class methods and programs in general make extensive use of
decision-based logic to differentiate what the program will do for
various cases.
As one example, the monitor blood pressure method in the
Vitals class needs to check blood pressure on a regular basis, update
the current blood pressure properties, and give a warning if there is a
low or high reading. The decision point is needed to give that warning.
Pseudo-code for that decision might be:
If systolic_pressure < 85 or diastolic_pressure < 50 then ‘identifies low condition
vitals_warning(lowbp) ‘starts the vitals_warning method with lowbp as Any information that goes into a program is called an input. Inputs may be data based storing variables or may be event based. In the inputs-process-outputs model for programming, the first section identifies all such inputs. As an example, a program might be designed that adds together two numbers. The inputs would be the two numbers being added together.
Search Terms: input-process-outputs model, programming variable, program inputs
“>input
Else ‘indicates what to do when the low condition is not true
If systolic_pressure >140 or diastolic_pressure > 100 then ‘identifies high condition
vitals_warning(highbp) ‘starts the vitals_warning method with highbp as input
Else ‘indicates what to when high condition is also false so normal
‘no warning action is necessary in this case
End If ‘exits the high blood pressure check
End If ‘exits the low blood pressure check
As another example, the add_course method in the Registration
class would need not only to add the course to the array for the student
but would also need to interact with a separate Course class to include
the student on the list for that course. It would also likely need to
interact with other system aspects like checking prerequisites and such,
but for the example, just consider that basic registration interaction
of adding to the course list and the student list. A decision point is
needed to address the situation where the course is full. Assume that
the Course class has a method called add_student() which returns either
“added” or “full”. Then, the decision statement for the add_course in
the Registration class might be:
If ThisCourse.addstudent(ThisStudent.ID) = “full” then ‘identifies that the course is full
The results that come out of a program are called the outputs. In the inputs-process-outputs model for programming, the final section presents the outputs to the user. As an example, a program might be designed that adds two numbers together. The output would be displaying the answer.
Search Terms: input-process-outputs model, programming outputs
“>Output(“We are sorry. That class is full. Please choose another class.”)
Else ‘this indicates when the full condition is not true
ThisStudent.Registration.registered_courses.Add(ThisCourse.ID) ‘adds course to array of courses
End If ‘closes the conditional statement
In the Discussion this week, numerous examples of classes with
associated variables and methods were generated. Choose one of the
methods that requires a decision be made by the program. It may be a
method from the class you described in the Discussion, a method from one
of the examples, or a method from a class described by one of your
colleagues.
- Give the associated UML class diagram and explain your
chosen method. Include what the method does, what class properties the
method accesses or writes, and what other aspects of the class or system
the method needs to interact with. - Focus in on the decision point in the method. Explain what
decision the method code has to make and why. What role does the
decision point play in the method? - Give pseudo-code with comments to explain each step for that decision using an if-then structure.
Integrate you method description and if-then pseudo-code into a
single document that fully explains the overall method, interactions
with other classes, and the role of the decision point in that method.
Integrate your method description, decision point analysis, and if-then pseudo-code into a single document with a cover sheet.
