else if statements

9

Upload: patrick-john-mcgee

Post on 13-Apr-2017

219 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Else if statements
Page 2: Else if statements

Today's Computing Challenge• Challenge One: Identify Else If statements in a piece of code and

understand why they are used.

• Challenge Two: Apply an Else IF statement to a piece of code.

• Aspire Three: To nest If statements into the lesson code to increase complexity. Apply different IF statements into the defined problem.

*Additional Extension create your own decision tree including description and comments into the code hint: use // for code comments

Page 3: Else if statements

Else IF Statements• In the last lesson we created a basic program that …..?

• Can you remember?

• The first part of the lesson was to create a simple

If (condition is true){Then output a message} else do this

Page 4: Else if statements

IF Statements - RecapJava CodeDrawing of a descision

Page 5: Else if statements

Else If adds more possibilities or choices

Page 6: Else if statements

Java CodeStart a new java application in Netbeans and call it esleif

Notice that we did not print out the grade until after the If statement block. This is because the result is assigned to the variable grade until the end.

Extension: Can you include some help for the user in the output window?

Page 7: Else if statements

Your turn! Adapt the code and expand!Include more ELSE IF statements to complete the grading system

Once complete take a print screen and upload to your OneNote.

Can you adapt the code to become more user friendly!

Can you add comments to your code to explain the process?Take new screen shot and upload to OneNote

Page 8: Else if statements

Your turn! Adapt the code and expand!Can you adapt the code and create a new appcalled ‘temperature’ Change the Grades to the following 1. Steaming hot = temperature above 92 degrees Celsius2. Very hot = temperature above 72 degrees Celsius3. Hot = temperature above 62 degrees Celsius4. Very Warm = temperature above 42 degrees Celsius5. Warm = temperature above 22 degrees Celsius6. Cold = temperature above 2 degrees Celsius

Page 9: Else if statements

Plenary• What variables did you create?

• How did you declare that variable in Java?

• Inside the If statement what does the >= mean?