You want to write a mobile application that will help with your monthly budget.
ID: 3856830 • Letter: Y
Question
You want to write a mobile application that will help with your monthly budget. You have decided to create a class that will do all of the calculations. Below is the pseudocode for this class.
class Budget
Class Constructor(NewIncome, NewExpenses)
income = NewIncome
expenses = NewExpenses
difference = 0
status = "nothing"
end class
CalculateDifference
difference = income = expenses
end
DetermineStatus
if difference > 100 then
status = "You saved this month"
else if difference > 50
status = "You did OK but watch your spending."
else if difference = 0
status = "You broke even"
else
status = "You spent more than you earned"
end
ReturnDifference
return difference
end
ReturnStatus
return status
end
Which statements below CORRECTLY derives status?
A.)
Call ReturnDifference
Call ReturnStatus
B.)
Call DetermineStatus
Call CalculateDifference
C.)
Call DetermineStatus
D.)
Call CalculateDifference
Call DetermineStatus
Explanation / Answer
Method CalculateDifference calculates the difference using income and expenses variables.
Based on the expenses calculated in method CalculateDifference, status is determined in the method DetermineStatus.
___________________________________________________________________________________________________________________
Option (A)
1. Method Call ReturnDifference returns difference which is not yet processed.
2. Method Call ReturnStatus returns status which can't be derived with out processing difference.
Hence this is not the correct option
___________________________________________________________________________________________________________________
Option (B)
1. Method Call DetermineStatus determines status with the help of difference which is not yet processed.
2. Method Call CalculateDifference calculates difference.
But the order of calls results in incorrect value for variable status.
Hence this is not the correct option
___________________________________________________________________________________________________________________
Option (C)
1. Method Call DetermineStatus determines status with the help of difference which is not yet processed.
So the function call results in incorrect value for variable status.
Hence this is not the correct option
___________________________________________________________________________________________________________________
Option (D)
1. Method Call CalculateDifference calculates difference first.
2. Method Call DetermineStatus determines status with the help of difference processed in CalculateDifference function call.
So the order of calls results in correct value for variable status.
Hence this is the correct option
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.