CS1004 Homework #1
Due on February 8, 2005 at 11:00am

There are two parts to this homework: a written component worth 9 points, and programming component worth 16 points.  Submission instructions are available here.

Written questions

As to be described later in the homework submissions instructions, you may submit this as a hardcopy, or as a file along with your programming problems in one of four formats (Word, PDF, HTML, or plaintext).

  1. (1 point) Register on the class webboard.  You can do so by navigating to http://cs1004.cs.columbia.edu/webboard.html and following the instructions.  (You do not need to make any posts now, but the username/password will also be important later on when grades are uploaded to the webpage.)  You do not need to write anything in the submission itself; our TAs will check to make sure you've followed this step.
  2. (3 points) As demonstrated in chapter 1 of Schneider/Gersting or in the slides, pick one everyday activity you do and write out a step-by-step algorithm for it.  Make sure to use iterative or conditional constructs as necessary.  Your algorithm must have at least 6 steps, and should assume a 12-year-old as a computing agent (i.e., skilled in reading and writing English, able to follow steps, but not aware of much more than that).
  3. (5 points) You're given the following brainteaser: "Three humans and three monkeys (one big, two small) need to cross a river. But there is only one boat, and it can only hold two bodies (regardless of their size), and only the humans or the big monkey are strong enough to row the boat. Furthermore, the number of monkeys can never outnumber the number of humans on the same side of the river, or the monkeys will attack the humans. How can all six get across the river without anyone getting hurt?"
    1. (3 points) Write out the solution as a series of sequential steps.
    2. (2 points) In a few sentences, explain what underlying principle(s) you used to decompose the problem into those steps.

"Programming" problems

As described below, you will submit this part of the assignment as two files: a README file that answers the relevant parts of #2 and #3, and a file named typescript that contains a demonstration of you compiling and executing your Java program.

  1. (0 points) Get a CUNIX account already if you don't have one.  Visit http://www.columbia.edu/acis/accounts for more details.
  2. (8 points) Create a website on your CUNIX account.  The website must have the following:

    Use your creativity here!  A simple example of a website might be one with an "index" page with a picture of yourself, a "hobbies" page with your hobbies, and a "resume/bio" page with a brief resume or description of yourself.  If you already have a webpage, either make a specialized one for the class or modify it to conform to the above requirements.

    Particularly creative designs may earn up to one point of extra credit.  If you already are skilled at creating websites, another one-point extra credit possibility is to embed a Java applet on your webpage (feel free to copy somewhere on the web).

    Briefly (few sentences) explain your webpage design in the README file, and make sure to include a link to it (i.e., http://www.columbia.edu/~jjp32).

  3. (8 points) You're given the following Java "mystery" program, and your task is to get it to compile and figure out what it's doing.
    import java.util.Scanner;
    
    public class MysteryProgram {
      public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int n = s.nextInt();
        long j = 1;
        while(n > 0) j *= n--;
        System.out.println("The answer is " + j);
      }  
    }
    
    1. (2 points) Cut-and-paste this into your CUNIX account in a filename named MysteryProgram.java.  (Note that pasting in an X environment is a little tricky; you may find it easier to paste it into a file on your computer and upload it from there.)
    2. (2 points) Create a typescript of the program's execution.  This can be accomplished by running the journal command on CUNIX, which will start up a recorder of your CUNIX session.  Type in the commands (e.g., javac or java), and show the execution of the program at least once.  To exit the "journal", type in exit or press CTRL-D.  (Make sure to exit it as soon as you're done so the script file doesn't get too large, and let the journal program remove the control characters.)
    3. (2 points) In your README, use your best guess to explain what this program does and describe it in one sentence.  (Hint: If you're not sure, try different inputs in the program and see what it computes.  Make sure to start with small numbers, e.g., less than 10.)
    4. (2 points) Given a sufficiently large number for input, this program will no longer do what it's supposed to as per part (c).  State in your README what the largest properly-functioning number is, and make a guess (1-2 sentences of English) as to why Java's having trouble with bigger input.