LESSON 2: DECISION MAKING
LEARNING OBJECTIVES AND OUTCOMES
• Introduction
• If statement
• Switch statement
• The While Statement
• The Do Statement
• The For Statement
INTRODUCTION
A set of statements in Java program are normally executed sequentially in the order of their appearance. However, in practice there are number of instances and conditions when we have to change the order of execution of statements. This involves certain type of decision-making to check whether the particular condition has occurred or not. Decision- making statements changes the flow of program based on those conditions.
Java possesses following decision-making statements:
1. If statement
2. Switch statement
3. Conditional operator statement
THE IF STATEMENT
In programming executing code when one condition happens rather than something else is very common. To control the flow of statements in such conditions, developers introduced if statement. If Statement in JAVA has following structure: if ( testing statement )
{
}
If statement is written in lowercase and test statement is mentioned inside round brackets. A pair of curly brackets is used to section off a chunk of code that we only want to execute if the test condition is satisfied. Some examples of decision making- if statements are as follows:
• If (total marks is less than 50) fail • If (door is open) enter • If (percentage is more than 75)
Permitted
• If (code is 0)
Switch is off
There are different forms of implementing if statement
Most decisions are made with analysis, but some are judgment calls not susceptible to analysis due to time or information constraints. Please write about a judgment call you’ve made recently that couldn’t be analyzed. It can be a big or small one, but should focus on a business issue. What was the situation, the alternatives you considered and evaluated, and your decision making process? Be sure to explain why you chose the alternative you did relative to others considered.
&& // is a logical and operator that if both the operands are non- zero, then the condition becomes TRUE.
-Declared the Strings to print outside of IF statement, added IF statement to check if the data
6. (TCO 3) Which pseudocode produces the same result as the following? if customerAge > 65 OR customerAge = 65 then
The use of break statement is unconditional and applied in any other loop or switch statement. The break will apply to a single level only. Java program develops a break statement with a label also. The continue statement once applied to the loops, skip the remainder of iteration and continues with the next iteration. Thus, it does not close the loop. In C# language, presence of each break or goto is a need for the switch case statement. EXIT statement in FORTRAN 90 is unconditional and applied to any other loop. It can be applied to any number of levels. FORTRAN 90 has a CYCLE statement that ensures the same work as C’s continue
Evaluates a condition and returns one value if the condition is true and a different value if the condition is false.
* Sample: The sample is limited to a small proportion of working professionals in Western Sydney and may not accurately reflect the population of working professionals.
Indicate whether the statement is true or false. If false, change the identified word or phrase to make the statement true.
The if statement is one of the vital among decision making statements and it is mainly used for controlling the execution flow of statements within a program. It is a two-way decision making statement that is used in conjunction with test expression. The general form is given as:
The rational decision-making model describes a series of steps that decision makers should consider if their goal is to maximize the quality of their outcome. In other words, if you want to make sure that you make the best choice, going through the formal steps of the rational decision-making model may make sense. The following are the steps taken to come to a rational decision: 1. Identify the problem, 2. Establish decision criteria, 3. Weigh decision criteria, 4. Generate alternatives, 5. Evaluate the alternative, 6. Choose the best alternative, 7. Implement the decision, 8. Evaluate the decision.
As stated by Prasad (2008), the managers should identify the different choices available in order to get most acceptable outcome of a decision. From searching different alternatives the managers can evade blocks in operations as choices are suitable if a particular idea goes wrong. Khanka (2000) expresses the view that selections can developed from in many ways such as can get from sources like experience, do training other organizations, and take others ideas and suggestions related in problems. Furthermore to improve alternatives solution the managers may investigation the signs of a problem for clues or fall back on intuition or result that stated by Griffin and Moorhead (2010). For an example in marketing department a non-programmed decision is compulsory the manager have to produce alternatives for raise market share. As McShane and Von Glinow (2000) pointed out that in a programmed decision is a standard operations is not to generate choice but can take out from the documented that already saved. Next an organizer should search the mission of a decision. In other words they need to define what is to be accomplished by it (Quick & Nelson, 2013). The decision criteria are important as mentioned by Dubrin (2002). The several criteria are consumers must aware of varies in quality of products, there not happen inflation, workers must consider the quality of improvements and lastly job satisfaction should not be reduce.
Programmed decisions are type of decisions which are routine and repetitive, of which are within the frame work of organization policies and rules. Such polices rules are established in advance to solve a re- occurring problems within the organization. Such programmed decisions are usually taken at lower management level and tends to have a short-run impact on organization.
We have to think about the qualitative factors that are involved in our decision making too. In the decision making process, as we saw in a case called The Nancy M. Hohman, we saw that many times the numbers will not speak louder than our personal preferences. The Nancy M. Hohman was a less than one year old ship, worthy US$ 40 million, carrying 200,000 tons of crude oil and 28 crew members and had an engine malfunction 9 miles way off the coast of South Africa. However, Port Elizabeth (the nearest one) was too small for the ship and the next close one was 380 miles away.
The purpose of this report is to give information on the subject known as Logical reasoning and its use in Computer Science and computers in general. A historical background behind logic and Logical reasoning is firstly given, followed by an overview of the modern subject and the types it’s divided into. The types are then explained. The overlap between the field of logic and that of computer science is also given an explanation. The report ends with a brief overview on the subject and its tie to computer science and computing.
TRUE/FALSE. Write 'T' if the statement is true and 'F' if the statement is false.