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!


  1. Mystery Code
  2. Triangle Area
  3. Flag of Belgium

  1. 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);
      }
    }
  2. 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).
     
  3. 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!