Lab 9, Part 1 ------------- This is the program that took in exam, CA and project marks and then echoed various outcomes. It was marked out of 5. a) You scored 0 if it didn't compile, or if your solution was wholly terrible. b) I tested your program on all 8 possibilities. You scored 1 if you did not get all 8 of them correct. c) If you got all 8 correct, you scored at least 2. For higher marks, you needed to find a good solution. The very best solutions (efficient, clear and maintainable) made clever use of both conjunction (or maybe disjunction), one-armed and two-armed or three-armed conditionals, nested-ifs and ifs in sequence. Lab 9, Part 2 ------------- This is the one about BMI. It was marked out of 5. Some of you lost marks because you did not calculate the user's ideal weight. Some of you lost marks because you did not output the user's 'category'. Some of you used only three or four categories, but the Wikipedia table had 8 - again you lost marks. To determine the category, a great long sequence of one-armed conditionals was not a good solution - you needed a multi-armed conditional. Some of you seem to think that the opposite of, e.g., < 16 is >= 16.1. But what happens to people whose BMI is 16.05? The opposite to < 16 is >= 16. (Similarly for < 40 and > 40. What about people whose BMI is 40?) The ambiguity in the table was what to do with 15, 16, 18.5 etc. Should you use < or <=. I didn't care which (although < is probably what was intended by the authors of the table). You lost marks if you were inconsistent. Otherwise, the question was a gift - it was really easy to score full marks. Lab 9, Part 4 ------------- This was the buggy water tax program. It was marked out of 4. I already presented a correct version of the program in lectures, so it should not have been difficult to fix this buggy version. There were three main things to fix: a) The student's if's were not mutually exclusive. b) In the case of high water usage, i) the student did not divide $extra_gallons by 1000 and floor it (or "(int)" it); ii) the student added 60, but he should have multipled 60 by the number obtained in (i); iii) the $first_tax should be based on 12000 gallons, not $num_of_gallons; iv) the student's program has no output for people who use > 12000 but < 13000. c) The student showered his program with "(int)"s - like confetti at the wedding of a pig. Every single one of them was pointless! For example: $flat_rate = (int) 120; Some of them showed a complete lack of understanding, e.g. $first_tax = (int) $num_of_gallons * 0.05; Because (int) has higher precedence than multiplication, it affects just $num_of_gallons, and not the whole calculation. To affect the whole calculation, you would need: $first_tax = (int) ($num_of_gallons * 0.05); (Even then, in this progranm, it's still not needed!) You should have removed *all* of the "(int)"s. You should have inserted just one (or "(float")) into the very first statement; and, of course, you needed to use floor or (int) after dividing by 1000. Lab 9, Part 5 ------------- This was the stamp duty question. It was marked out of 6. In some ways, it brought together everything we have covered in one straightforward question. So if you scored 6 out of 6, well done: you would appear to have mastered the Period 1 material :) 1) Your solution should start by getting the user's input. Most of you knew that you get one input per *group* of radio buttons, not one per button. So we have: $house = $_GET['house']; $buyer = $_GET['buyer']; $occupation = $_GET['occupation']; $price = (int) $_GET['price']; $area = (int) $_GET['area']; Note that only the last two need converting to int (or float). 2) Next you should deal with the exemptions. One approach is to specify who is exempt, in which case, you get a solution like this: if ( ( $house == 'new' && $buyer == 'first' && $occupation == 'owner' ) || ( $house == 'new' && $area < 125 ) ) { $duty = 0; } elseif ... // cheap houses elseif ... // medium-price houses else // expensive houses echo $duty; A variant of the above is to note that 'new' is common to both exemptions, and so instead write the following: if ( $house == 'new' && ( ( $buyer == 'first' && $occupation == 'owner' ) || $area < 125) ) Some of you preferred instead to write a test for people who are *not* exempt. The easiest way to do this is to negate the whole test for people who are exempt. Doing this gives a solution like this: $duty = 0; if ( ! ( ( $house == 'new' && $buyer == 'first' && $occupation == 'owner' ) || ( $house == 'new' && $area < 125 ) ) ) { if ... // cheap houses elseif ... // medium-price houses else ... //expensive houses } echo $duty; If you tried to negate the individual tests, you probably got it wrong. The best thing to do is use de Morgan's laws on the above. The result is: if ( ( $house != 'new' || $buyer != 'first' || $occupation != 'owner' ) && ( $house != 'new' || $area >= 125 ) ) or, equivalently: if ( ( $house == 'old' || $buyer == 'existing' || $occupation == 'investor' ) && ( $house == 'old' || $area >= 125 ) ) or: if ( $house == 'old' || ( ( $buyer == 'existing' || $occupation == 'investor' ) && $area >= 125 ) ) These are quite counter-intuitive, which is why you got them wrong if you chose not to use de Morgan's laws. 3) Finally, the calculations. Cheap houses (<= 125000): $duty = 0; Medium-priced houses (>125000 but <= 1000000): $duty = ($price - 125000) * 0.07; Expensive houses (> 1000000): $duty = (875000 * 0.07) + ($price - 1000000) * 0.09; There were lots of errors from not reading the question properly, e.g. using 875000 instead of 1000000, or taxing the whole $price instead of separate parts of the price.