CSCI 201 Fall 2002: Assignment 2


Assignment 2, Program 1:

Write a program called LeapYear to perform the task described in problem 3.2 on page 201 of your text.

Assignment 1, Program 2:

Write a program named Backwards that reads a four-digit number and then outputs that number one digit per line in reverse order. This is the same program that you were originally asked to write as part of assignment 1, before the assignment was shortened. Now that we know more, lets add a little bit to the program. In addition to printing the digits of the number that the user enters, your program should also output the number of odd, even, and zero digits in that number.

Sample output from your program should look as follows (user inputs are itialized):

enter a four digit integer: 1998
In reverse order, the digits are:
  8
  9
  9
  1
The number contained 3 odd digits
The number contained 1 even digits
The number contained 0 zeros

Hint: If a variable named number initially stores the value 1998. What's the result of evaluating these two expressions?

  number % 10
  number / 10;

General Instructions

Because both of your progams will be semi-automatically graded, you must observe the following restrictions:

Programming Style

Note that 10% of your program grade is based on the readability of your program. This includes things like style, comments, and the naming of variables. Make sure you include a comment at the top of each program with your name, course and purpose of the program specified.

// Name: YOUR NAME HERE // // Course: CSCI 201 // // Purpose: purpose of program here //

Submitting Programs

Both programs written for this assignment must be turned in by transferring the respective java source code files to your ftp directory for this class. For each program, only the source code file (i.e., LeapYear.java, and Backwards.java) should be turned in and the files must have exactly those names. You were shown how to transfer files to your class ftp directory in lab 1.