Computer Science 15-100 (Lecture 18), Spring 2009
Homework 0
(Pass/Fail)
Due: Thu 15-Jan-2009 at 11:59pm (email copy) and at Friday's
class/recitation
(identical physical copy)
(no late submissions accepted).
Read these instructions first!
- This homework is Pass/Fail. To pass, you must get a passing
mark (60% or higher) on each of the three questions. Passing marks
will not be factored into your semester grade, but failing marks will count
as a 0 in your homework average.
- Be sure to include your name, your Andrew ID, and your section clearly on the top of each file in your assignment.
- Also include a timesheet logging all the time you spent on the
assignment.
While this is required, you will not be graded on your number of hours,
but this information will be helpful to the course staff. You can
include the timesheet in the header of a Java file or in its own text file (timesheet.txt).
It would be most helpful if you indicate roughly which problems you were
working on at various times (so we can identify if there are any issues with
time demands of these questions).
- For non-programming problems:
- Place all your solutions to the non-programming problems in a single
file named Hw0 (with whatever extension is appropriate for the format you
choose, such as Hw0.txt or Hw0.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 Hw0Foo.java, the main class in that file must be Hw0Foo.
- 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-hw0" (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.
- Mystery Code
- Triangle Area
- Flag of Belgium
- Mystery Code
In the written portion of your submission, answer this question:
under what conditions in general will the following program output
zero?import java.util.Scanner;
class MyCode {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an integer: ");
int x = scanner.nextInt();
System.out.print("Enter another integer: ");
int y = scanner.nextInt();
// Hint: x/y is INTEGER division, where the remainder is ignored!
int mystery = (x/y) + (y/x) - 2;
System.out.println(mystery);
}
}
- Triangle Area
In the file Hw0TriangleArea.java, write a program that reads in the base
and height of a triangle and prints out its area (where the area of a
triangle is one half the product of its base and height). You should
use integer division (so the remainder will be ignored). While you
must use good prompts and meaningful output, you do not have to worry about
illegal inputs (such as a non-positive or non-integer base or height).
- Flag of Belgium
In the file
Hw0FlagOfBelgium.java, write a program that displays the flag of Belgium:
(larger
image with details)
Note: This flag image is from the very informational
CIA
World Factbook, which includes a
flags-of-the-world page.
Your program should paint three filled rectangles, and should use built-in
colors (so the colors might not match exactly, but they will be close).
Also, your flag may not be fixed-sized, but rather must entirely fill the
window, even when the window is resized. While the window's size may
change, you may assume the window will be roughly "flag-shaped" -- you will
not be graded on how your flag appears in, say, a tall thin window (which is
not at all "flag-shaped").
Carpe diem!