v22.0310-003: Homework 1

Due date: Tuesday, September 21. Remember the no late homework policy.

INSTRUCTIONS: Hand in this homework by email to our friendly TA, archi@cs.nyu.edu. Include the entire assignment in a single email message. Please use only plain text message. Do not send attachments (MIME type) or anything like that. If you are using pine email, you can include your program files into the message body as plain text by using the ^R command. Make sure that the subject line of your email says ``HW1 by <your-name-here>''.

JAVA INFORMATION: You will need to program in Java for this homework. Besides my general Java Resource Page, our T.A. has tried to gather all the basic information you will need in order to solve this porgramming problem into one convenient location: CLICK HERE


  1. [5 Points] Send us a copy of the response from majordomo (the mailing list server) saying that you have been added to the class mailing list. The copy ought to contain the usual email header information such as time and date, message ID, etc.

    Notes: If you have deleted that message already, then first un-subscribe yourself, and then re-subscribe yourself to the mailing list. Also, DO NOT SEND any extraneous stuff (especially the long help message that you may have requested from majordomo).

  2. [10 Points] The fastest way to learn to program in Java or any language is to take simple working examples and modify them. We encourage this approach whenever possible (remember, our goal is not to teach programming, but to USE it for understanding algorithms). Study the following sample program carefully: Factorial.java. For more sample programs click here.

    We ask you to compile and run Factorial.java. You are asked to detect the SMALLEST integer n such that Factorial(n) gives you the wrong answer. Call this smallest value maxN. Note: this number may depend on the computer system on which you run. Tell us three things:

    (i) the value of maxN on your computer system
    (ii) your computer system (hardware and software)
    (iii) how you compute this value (you can do this ANY WAY you like).
  3. [20 points] Modify the "Factorial.java" into a new program called "fact.java". Your program detects if the user's input is incorrect and prints a helpful informative message that corresponds to the error. Here are the errors you must detect:
    (i) The user does not provide any arguments
    (ii) The user provides more than one argument
    (iii) The user does supply an argument but it is not an integer
    (iv) The user provides an integer argument, but it is not between 0 and maxN, inclusive.

    HINT: for (iii), you will need to catch exceptions. For this purpose, you might want to study the program Hello.java and also read up briefly about exceptions.

    Send us the java source program only (but not the compiled program).

    GENERAL RULE ABOUT PROGRAMMING ASSIGNMENTS: if your program does not compile, you get 0 point. We suggest carefully worded comments (multiline comments, /* ... */, as well as single line type, //). Make sure your program is called "fact.java", because this simplifies our grading task.