Wednesday, February 18, 2009

KURL DAY IF/ELSE STATEMENTS

KURL DAY 2/18/2009
Objectives: Students should be able to understand how to write if/else statements, use comparision operators, and convert strings using upper and lowercase methods.

1. TEAM READING: PAGES 196- TOP OF 210: SPLIT THE PAGES. REVIEW CHARTS. PRACTICE WORKSHEET.

2. SUMMARIZE YOUR READING IN A DIAGRAM. POST IN A COMMENT. READ OTHER COMMENTS.

PRACTICE STATEMENT WRITING WORKSHEET: POST IN A COMMENT.

1. Write and if statement that displays the temperature if the temperature is greater than 75 degrees.
2. Write and If/Else statement that displays your GPA if it is greater than 2.5 otherwise, displays message “You Need to Improve your GPA”.

COMPARISION OPERATORS

1. Write a statement if statement show a true condition of two variables that are equal.
2. Write an if statement that show that a condition is not equal to the name “Smith” then display all other names.
3. Write an if statement that shows if the tax rate is great than 7% then provide a discount of 1% .

UPPER/LOWER METHODS

1. Write a statement to convert the name SMITH to all lower case.
2. Write a statement to convert the name “smith” to all upper case.

15 comments:

  1. If Selection Structure
    Take real life situations and apply it to VB.

    'Find the temp
    'if the temp = 75 Then
    'We stated that if temp = 75 Then do This
    label1.Text = "The Temp is 75"
    'To end the if statement use
    End if
    'Display the temp

    If/Else Selection Structure
    Lets say you want it to do something if the temp is not 75. Then you use the If/Else Statement.

    'Get Temp
    If temp = 75 Then
    'If temp is 75 Then
    label1.Text = "Temp is 75"
    'But if it is not then else it will do
    Else
    label1.Text = "Temp is not 75."
    End If

    When using if statements think about how the layout of it will work.

    Math is used in If statements like =, >, <, >=, or <>.

    ReplyDelete
  2. 2 types of paths. True and False.

    when creating an if then code start off with with then the changing varable then put the true path down.

    = equals
    > greater than
    >= greater than or equal
    < less than
    <= less than or equal
    <> not equal to

    make upper case string.toupper()
    make lower case string.tolower)

    PRACTICE STATEMENT WRITING WORKSHEET

    1. If temperature > 75 Then
    display temperature
    2. If Gpa > 2.5 Then
    display GPA
    Else
    display "You Need to Improve your GPA"

    COMPARISON OPERATORS

    1. If Label1 = Label2 Then
    Display picture
    2. If Label1 <> Label2 Then
    display "Smith"
    3 If taxrate > .07D Then
    taxrate = taxrate - .01D


    UPPER/LOWER METHODS

    1. Smith.text = Smith.toUpper()
    2. Smith.text = Smith.textdottoLower()





    CRAIG SHERWOOD
    MICHAEL HUANG
    1st Period


    micheal urow

    ReplyDelete
  3. Practice Worksheet:

    Comparison Operators:
    1. If temperature > 75
    Display temperature
    endif
    2. If GPA > 2.5
    Display GPa
    Else
    Print “You Need to Improve your GPA”
    endif

    Comparison Operators:

    1. If variable1 = variable2 Then
    Condition = True
    endif
    2. If name <> Smith Then
    Display allNames
    endif
    3. If taxRate > 7%
    price * .99
    Display taxRate
    endif

    Upper/Lower Methods:

    1. nameSmith = nameSmith.ToLower()
    2. nameSmith = nameSmith.ToUpper()

    Summary:
    Decision Structure or Selection structure is a structure comprised of If, If/Then, If/Then/Else, and Case structures. Each of these structures has a "true" path defined by the "condition" yet only some of them may contain a "false" path recognized my the operator "else". The operator "endif" represents the ending of the statement. If statements primarily use Comparison Operators or Relational Operators to define s true statement. These operators include =,<,>,<=,>=,and <>. The Upper method and the Lower methods are coding methods added to change a string from upper case to lower case or vice-versa. You can also use Logical Operators to define a statements condition. These operators include Not, And, Or, and Xor.

    Stuart R.
    Vlad

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. The Selection Structure
    • Making decisions
    • Using If/Else Statements: If part is true, the else part is the false condition
    • End if ends the selection structure/statements
    • Psuedocode: English languages statements used to flowchart & program applications before writing code
    • Symbols for flowcharts:
    1. Oval for starting and stoping the operation.
    2. Rectangle for the process symbol
    3. Parallelogram is the input.output selection/repetition symbol.
    • Comparisonoperators =(equal to) >(greaterthan) >=(greatererthanorequalto)
    • <(lessthan) <=(lessthanorequalto) <>( not equalto)
    Practice Statements
    1. If Temp > 75 Then TemperatureTextBox.Text = “Temperature”
    2. If GPA < 2.5 Then TextBox.Text = “Yoy Need to Improve your GPA”
    Comparison Operators
    1. If Variable1 = variable2 Then statement = True
    2. IF Name <> “Smith” Then display other names
    3. If TaxRate > 7% Then Discount = 1%
    Upper/Lower Methods
    1. If nameTextBox.Text = nameTextBox.Text.ToLower ( )
    2. If NameTextBox = NameTextBox.ToLower

    ReplyDelete
  6. The selection structure is also called the decision structure. You use this when you want a program to make a decision or comparison and then select one of two paths, depending on the result of that decision or comparison. Condition is the portion in italics, it specifies the decision you are making and is phrased so that it results in either a true or false answer only. Example: it is raining (true) or not raining (false). An If selection structure contains only one set of instructions, which are processed when the condition is true. An If/Else selection structure contains two sets of instructions: one set is processed when the condition is true and the other set is processed when the condition is false.
    -------------------------------------------------1) If temperature > 75 Then
    -------------------------------------------------
    2) If GPA > 2.5 Else
    Display “You need to improve your GPA”
    -------------------------------------------------
    1) If equal <= rate Then
    -------------------------------------------------
    2) Write an if statement that show that a condition is not equal to the name “Smith” then display all other names.
    -------------------------------------------------3) If tax rate > 7% Then
    Provide a discount of 1%
    -------------------------------------------------
    1. Smith.text = Smith.texttoUpper()
    -------------------------------------------------
    2. Smith.text = Smith.texttoLower()
    ------------------------------------------------

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. karolina barreto
    alex anderson

    THE SELECTION STRUCTURE

    • Selection or Decision structure: is used when u want a program to make decisions or comparisons and then select one of two paths, depending on the result of that decision or comparison.

    o EX: if it is raining
    wear a raincoat
    bring an umbrella

    • A condition specifies the decision you are making and is phrased so that it results in either a true or false answer only.



    WRITING PSEUDOCODE FOR THE IF AND IF/ELSE SELECTION STRUCTURES


    • If selection structure: only one set of instructions.

    o Processed when the condition is true.

     EX: 1. Get the part number and price
    2. If the part number is “AB203”
    (TRUE PATH) calculate the price by multiplying the price by 1.1
    (TRUE PATH) display “Price increase” message
    end if
    3. Display the part number and price


    • If/Else selection structure: two sets of instructions.

    o One set is processed when the condition is true and the other set is processed when the condition is false.

     EX: 1. Get the sales amount
    2. If the sales amount is greater than 1500
    (TRUE PATH) calculate the commission by multiplying the sales amount by 0.2
    (FALSE PATH) calculate the commission by multiplying the sales amount by 0.1
    end if
    3. Display the commission

    • True path: path you can follow when the condition is true

    o Ends when you come to the “else”

     If there is no “else”, when you come to the end of the selection structure. (end “if”)

    • False path: instructions between the “else” and the “end if”

    • Selection/repetition symbol: (diamond) used to represent both selection and repetition structures


    CODING THE IF AND IF/ELSE SELECTION STRUCTURES
    • If..Then..Else Statements

    o EX:
    If partNumber = “AB203”
    Price = price * 1.1
    messageLabel.Text = “Price increase”
    End if

    o EX:
    If sales > 1500D Then
    Commission = .02D * sales
    Else
    Commission = .01D * sales
    End if



    Using Comparison Operators – Swapping Numeric Values
    · Dim temp As Integer declares a variable named temp
    · Variables declared within a statemant block have Block Scope.
    · Temp= number1, assigns the value in the number1 variable to the temp variable.
    · The Concatenation Operator (&) is used to connect or link strings together.
    · ControlChars.NewLineconstant advances the insertion point to the next line in the messageLabel.
    Using Compaison Operators – Ex 2
    · operationTextBox.Text statement assigns the contents of the operationTextBox’s text property to the operation variable.
    · ToUpper method used to convert to uppercase.
    · ToLower method is used to convert to lowercase.
    · If CharacterCasing property is left at its derfault value, then normal coding will not work.







    If temp > 75
    Display temp
    end if


    If GPA > 2.5
    Display GPA
    Else
    Print “You Need to Improve your GPA”
    end if


    If variable1 = variable2 Then
    Condition = True
    end if

    If name <> Smith Then
    Display allNames
    end if

    If taxRate > 7%
    price * .99
    Display taxRate
    end if


    1. nameSmith = nameSmith.ToLower()
    2. nameSmith = nameSmith.ToUpper()

    ReplyDelete
  10. Page 205: Linking two strings/variables together
    Ambersand & (Shift7 Key)

    Joining the variables together, you can create a sentence....

    Combine different data types as well with this ambersand.

    ReplyDelete
  11. Practice Statement Writing Worksheet:

    1.) If temperature > 75
    Display temperature
    endif

    2.) If GPA > 2.5
    Display GPA
    Else Print “You Need to Improve your GPA”
    endif

    Comparison Operators:

    1.) If variable1 = variable2 Then
    Condition = True
    endif

    2.) If name <> "Smith" Then
    Display allNames
    endif

    3.) If taxRate > 7%
    price * .99
    Display taxRate
    endif

    Upper/Lower Methods:

    1.) nameSmith = nameSmith.ToLower()
    2.) nameSmith = nameSmith.ToUpper()

    Summary:
    Decision Structure, Selection structures, and Case structures are structures that are comprised of: If, If/Then, If/Then/Else statements. These structures have a "true" path(boolean) defined by the condition. But, only some of them may contain a "false" path(boolean) recognized by the operator: "else", and the operator "endif" is the ending of the statement.

    If statements primarily use Comparison Operators or Relational Operators to define a true statement, such as: =,<,>,<=,>=,and <>.

    The Upper method and the Lower methods are coding methods added to change a string from upper case to lower case.

    You can also use Logical Operators to define a statements condition, such as: Not, And, and Or.

    ~Andres Casallas
    ~Brandon Huggins

    ReplyDelete
  12. <= - less than or equal
    <> - not equal to

    Make lower case string.tolower)
    Make upper case string.toupper()

    Upper/Lower Methods

    1. Smith.text = Smith.toUpper()
    2. Smith.text = Smith.textdottoLower()

    Comparison Operators:
    1. If temperature > 75
    Display temperature
    endif
    2. If GPA > 2.5
    Display GPa
    Else
    Print “You Need to Improve your GPA”
    endif


    Pracitce Statment Writing Worksheet

    1. If temperature > 75 Then
    display temperature
    2. If Gpa > 2.5 Then
    display GPA
    Else
    display "You Need to Improve your GPA"


    Brian Geertsma
    Arash Afshar

    ReplyDelete
  13. By Nestor J. Maysonet & David M. Galvez

    (www.rpgbuilder.blogspot.com) For diagram.

    PRACTICE STATMENT

    1.If temperature > 75
    Then display temperature
    Endif
    2.If GPA > 2.5
    Then display GPA
    Else
    Display "You Need to Improve Your GPA"
    COMPARISON OPERATORS

    1. If Sales = Profit Then Calculate Net Profit

    2. If TextBox.Text <> "Smith" Then display allNames

    3. If TaxRate > .07 Then calculate (TaxRate * Price - .01 * Price)

    UPPER/LOWER METHODS

    1. If name = "Smith" Then name.ToLower()
    2. If name = "Smith" Then name.ToUpper()

    ReplyDelete
  14. Temp/GPA

    If temperature >75 then display
    End If
    If GPA > 2.5 then display GPA
    Else
    GPALabel.Text = (“You need to improve your GPA”)

    Comparison

    1. If variable1 = variable2 Then
    Condition = True
    EndIf
    2. If name <> Smith Then
    Display allNames
    EndIf
    3. If taxRate > 7%
    price * .01D
    Display taxRate
    EndIf

    Upper/Lower

    1. Smith.text = Smith.Text.toUpper()
    2. Smith.text = Smith.Text.toLower()

    ReplyDelete
  15. Coding The If And IF/ELSE Selection Structure

    Syntax

    If Company SBS Then


    Economy infrastructures in “X” enterprise reduce approximately 25% of overall total plus an interest rate per employee of $500


    If We Find infrastructure
    If ITP = 500
    INf>500+25


    If End


    Display Interest

    If/Else Structure
    Let’s infer the company is reducing the infrastructure to as minimal
    possible.

    If discount is 25% Then you use
    If/Else Structure

    Get INF

    If INT = 500 Then
    “If INT is 500 Then
    Label.1_Sintax But if Not
    Else


    Label1.TEXT = 25x =500
    End IF



    As in math is used the percentage of discount/Interest Rate.

    ReplyDelete