RU beehive logo ITEC dept promo banner
ITEC 120
2012fall
dbraffitt
ibarland

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs

lab04b
finishing turtles
and a chance to try booleans

Complete the previous lab, and have your file checked off (for you and your partner).


Extra credit

If you finish that early and want to working on something more, there is a small amount (4pts max, graded strictly) of extra credit for completing the following and submitting your improved code to to D2L > dropbox > lab04b-ec.
(Be sure you also check off your unimproved code above (perhaps making a backup of it), before starting on this!)

  1. Make a copy of your entire function triangle, re-named to (say) triangle_v2, and change it so that it takes three arguments: not just the Trtl and the size of the triangle (a double), but also whether to draw a “right-handed” or “left-handed” triangle, the difference being that all the turns are reversed (e.g. -120 instead of +120). What new Java type from yesterday should we use, to represent the desired handedness, in the signature? Hint: don't use String!

    Be sure to factor out any repeated code; your upgrade should add about five (fairly simple) lines of code, but should not double the number of lines of code.

    hint: Don't think of it as “either multiply all my turns by -1, or do nothing”; instead think of it as “either multiply all my turns by -1, or multiply them by +1.”. This way, the only difference is the particularly number to multiply by. This is reminiscent of the trick we used for getting the plural case right in toppingMsg from yesterday's lecture.

  2. Re-write triangle (which draws a right-handed triangle) to be a one-line function which calls triangle_v21.

  3. Write zag_v2 similarly (and then rewrite the original zag to be a one-liner).

  4. Finally, write smileyFace_v2 which accepts a handedness as input; all rotations should be in the other direction (but movements left the same). (Can you explain the result?)


1 Actually, in Java you can name both functions triangle; depending on whether it's called with two arguments or three, Java knows which of your two functions to call. This is called overloading the function name.      

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs


©2012, Ian Barland, Radford University
Last modified 2012.Sep.25 (Tue)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme