Friday, February 14, 2014

Section 4.2 If Blocks: If Statement




40360:  Write a conditional that assigns true to the variable fever is the variable termperature is greater than 98.6.

If (temperature > 98.6) Then
fever = true
End If


40361:  Write a conditional that assigns 10,000 to the variable bonus if the value of the variable goodsSold is greater than 500,000.

If (goodsSold > 500000) Then
bonus = 10000
End If


40362:  Write a conditional that decreases the variable shelfLife by 4 if the variable outsideTemperature is greater than 90.

If outsideTemperature > 90 Then
shelfLife = shelfLife - 4
End If

40363:  Write a conditional that multiplies the values of the variable pay by one-and-a-half if the value of the boolean variable workedOvertime is true.

If workedOvertime = true Then
pay = pay * 1.5
End If

41061:  Assume that isIsosceles is a bool variable, and that the variables isoCount, triangleCount, and polygonCount have all been declared and initialized.  Write a statement that adds 1 to each of these count variables (isoCount, triangleCount, and polygonCount) if isIsosceles is true.

If isIsosceles = true Then
isoCount = isoCount + 1
triangleCount = triangleCount + 1
polygonCount = polygonCount + 1
End If

41060:  Assume that the variables gpa, dealsnList and studentName, have been declared and initialized.  Write a statement that both adds 1 to deansList and prints studentName to standard out if gpa exceeds 3.5.

If gpa > 3.5 Then
deansList = deansList + 1
MessageBox.Show(studentName)
End If




40217:  Given the integer variables x and y, write a fragment of code that assigns the larger of x and y to another integer variable max.

If x > y Then
max = x
Else
max = y
End If


41066:  Clunker Motors Inc is recalling all vehicles from model years 2001 - 2006.  Given a variable modelYear write a statement that prints the message "RECALL" to standard output if the value of  modelYear falls within that range.

If modelYear >= 2001 And modelYear <= 2006 Then
MessageBox.Show("RECALL")
End If

41069:  Clunker Motors Inc is recalling all vehicles in its Extravagant line from model years 1999 - 2002.  Given an int variable modelYear and a string modelName write a statement that prints the message "RECALL" to standard output if the values of modelYear and modelName match the recall details.

If modelYear >= 1999 And modelYear <= 2002 And modelName = "Extravagant" Then
MessageBox.Show("RECALL")
End If

41071:  Clunker Motors Inc is recalling all vehicles in its Extravagant line from model years 1999 - 2002 as well as all vehicles in its Guzzler line from model years 2004-2007.  Given an int varialbe modelYear and a string modelName write a statement that prints the message "RECALL" to standard output if the values of modelYear and modelName match the recall details.

If (modelYear >= 1999 And modelYear <= 2002 And modelName = "Extravagant") Or (modelYear >= 2004 And modelYear <= 2007 And modelName = "Guzzler")  Then
MessageBox.Show("RECALL")
End If

41065:  Clunker Motors Inc is recalling all vehicles from model years 1995 - 1998 and 2004 - 2006.  Given a variable modelYear write a statement that prints the message "RECALL" to standard output if the value of modelYear falls within those two ranges.

If (modelYear >= 1995 And modelYear <= 1998) Or (modelYear >= 2004 And modelYear <= 2006)  Then
MessageBox.Show("RECALL")
End If




41116:  Clunker Motos Inc is recalling all vehicles from  m odel years 2001 - 2006.  Given an int variable modelYear write a statement that prints the message "NO RECALL" to standard output if the value of modelYear DOES NOT fall within that range.

If modelYear < 2001 Or modelYear > 2006 Then
MessageBox.Show("NO RECALL")
End If

1 comment: