Some students have struggled with the logic required to complete the call cost calculator exercise.
Once the first two price plans have been coded correctly the rest are easy.
The pre-pay plan is simple because each minute, text, or mb used is charged per unit.
If if mins were 8c, texts 6c, and data 2c per mb
the calculation looks something like:
total = mins * .08 + texts *.06 + mbs * .02
However where a plan comes with some free usage for a set minimum fee and this need to be accounted for.
Suppose a price plan costs €20 and comes with 50 free minutes and customers are charged 8c per extra minute.
It's tempting to say that
extramins = mins - 50
But wherever mins in less than 50, the phone company would be giving money back for unused minutes. It's only correct to say extramins = mins - 50 when mins is greater than 50. Furthermore, if mins is less than 50 then the number of extra minutes is zero.
So the code would look something like
if mins > 50 then
extramins = mins - 50
else
extramins = 0
end if
This is the pice of the puzzle that most students who had difficultly failed to figure out.
However the calculation of the extra minutes, texts, and data are independent of each other.
Eventually the final calculation might look something like:
totalcost = 20 + extramins * .08 + extratexts *.07 + extradata * .03
It doesn't make sense to check to see
if (mins > 50) && (texts > 100) && (data >100)
The extra minutes, extra texts, and extra data, must be calculated independently of each other.
The javascript part of the exercise didn't seem to pose any major problems for students. Students who are weak in programming may want to revisit some of the exercises they did in first year.
Wednesday, October 7, 2015
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment