Computer Science APEA 15-100, Summer 2009
Homework 2
Due:  Wed 1-Jul-2009 at 8:59am (email copy
and identical printed copy)
(no late submissions accepted).


Read these instructions first!


  1. Reading
    Read a good portion of Chapter 1 carefully (you'll have tonight and tomorrow night to finish it in time for Thursday's quiz, which covers all of Chapter 1).
     
  2. Book Problems
    Do the following Exercises from Chapter 1 (pp 51-54):
    Exercises 1.3abd, 1.4, 1.5, 1.20.
     
  3. Two's Complement
    Convert the decimal value -13 into 5-bit 2's complement.  Hint:  first find +13, then negate it.
     
  4. Triangle Area
    Write a program, Hw2TriangleArea.java, that reads in the base and height, in integers, of a triangle, and prints out the triangle's area (also as an integer).  Your program should use integer division.  You may assume the user enters only positive integers for the base and height.
     
  5. Flags of the World
    Using the techniques covered in class and in the lab, draw the following flags so that they fill the entire window and maintain proper proportions as the window is resized (to reasonably flag-shaped dimensions).   You do not need to color match here, but you should use the closest pre-defined color. 
     
    1. Flag of Benin
      In the file Hw2FlagOfBenin.java, write a program that displays the flag of Benin:
        (larger image with details)
       
    2. Flag of Panama
      In the file Hw2FlagOfPanama.java, write a program that displays the flag of Panama:
        (larger image with details)
      Draw the stars as their bounding circles.
       
    3. Flag of Azerbaijan
      In the file Hw2FlagOfAzerbaijan.java, write a program that displays the flag of Azerbaijan:
        (larger image with details)
      Draw the (many-sided) star as its bounding circle.  Note that you should draw the crescent properly.
       
  6. Bonus/Optional:  Sum of Odd Digits
    Write a program, Hw2SumOfOddDigits.java, that reads in a possibly-negative integer in the range [-999, +999], and prints out the sum of all the odd digits in that number.  For example, if the user inputs -361, your program would output 4 (the sum of 3 + 1).  Your program is not responsible for numbers outside the given range.  Note that you may not use "if", ternary operators (?:), or any conditionals or anything else we have not covered.  This can be done with simple arithmetic.
     

Carpe diem!