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!
- Be sure to include your name, your Andrew ID, and your section clearly on the top of each file in your assignment.
- For non-programming problems:
- Place all your solutions to the non-programming problems in a single
file named Hw2 (with whatever extension is appropriate for the format you
choose, such as Hw2.txt or Hw2.html, etc). You must use one of these
file formats: plain text (txt), or RTF, or HTML, or Word (doc, not docx), or
PDF. No other file formats will be accepted.
- Show your work. Correct answers without supporting
calculations will not receive full credit.
- For programming problems:
- Place each solution in its own file named exactly as given below, and
with a class name that exactly matches the file name. So if the file name
is Hw2Foo.java, the main class in that file must be Hw2Foo.
- Try to use well-named variables, proper indenting, reasonable commenting,
etc.
- Note: You may not use Java concepts we have not yet covered,
including loops (do/while/for), conditionals
("if" statements or tertiary operators (?:)), arrays, or methods
from any classes in java.util.* (besides Scanner or others we explicitly
use) to solve these problems
(which isn't a problem for most of you, seeing as we have not yet covered
these!). While they may be helpful, every problem here is solvable without
them, and they are not permitted for now.
- What to submit
- Create a submission directory like this: "koz-hw2" (replace
"koz" with your andrew id)
- Place all the files you are submitting in that directory, zip that
directory, and submit the zipped directory
- How to submit
- Send an email with the zipped submission directory as an attachment
to your CA by the submission deadline. Do not miss the deadline,
even by one minute! Email problems are not a valid excuse
for late submissions.
- It is recommended
that you "cc" yourself in that email, too, just to confirm that you properly
sent the email.
- Note:
- Improper submissions will be penalized up to 10 points and may be
rejected.
- Late submissions will be rejected.
- 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).
- Book Problems
Do the following Exercises from Chapter 1 (pp 51-54):
Exercises 1.3abd, 1.4, 1.5, 1.20.
- Two's Complement
Convert the decimal value -13 into 5-bit 2's complement. Hint:
first find +13, then negate it.
- 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.
- 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.
- Flag of Benin
In the file Hw2FlagOfBenin.java, write a program that displays the
flag of Benin:
(larger
image with details)
- 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.
- 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.
- 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!