Selection/Decision Structures
Another collection of the most
fundamental structures has to do with making decisions or branching
within a program.
For example, the tax rate depends on income level. In order to compute taxes appropriately, a programmer needs to use different rates depending on the income levels. There are endless examples of such situations. The following three diagrams represent the three fundamental selection/decision structures. The first one is the basic If - Then structure. Though the syntax is different in Java and doesn't require the then word. For example, if someone has a grade above a particular level then they should get an A. |
The next structure relates to having another option built in if the condition being evaluated is false. For example either someone passes a class or they fail it. If their grade is above a certain level, they pass. Else they fail. This is an If - Then - Else sort of structure, though the syntax is different in Java. |
Finally, we have situations where there is something that has some specific varied outcomes such as several different grade values, income tax brackets or paying for PMI on a mortgage. These sorts of things result in a large variety of different cases and implemented through a switch structure in Java. |