Assignment #1

Due: Sat, May 22

From the textbook, do Exercises 2.32, 4.31, and the following problem (also note extra instructions below).


Additional Problem

Write a program that will read an unspecified number of non-zero integers and determine how many positive and negative values have been read, as well as the total and the average of the input values. The input ends with the input of 0. Once all numbers have been input, display these results (positives, negatives, total, average). The final 0 is just a signal to end the input -- it does NOT count as one of the values.

Filenames should be Note that these filenames all start with a capital letter. Please make your filenames (and class names) match mine exactly.

To do these exercises, you will need the MyInput class that was shown in lecture. Paste this class into each of your own program files, and make sure to put the import java.io.* line at the top.


Extra Instructions

  1. For 2.32 (page 80), add in error-checking to insure that the user entered a 5 digit number. If a number with fewer or more digits is entered, print an error message and make the user re-enter (until they get it right).
  2. For 4.31 (page 166), there are two programs to write. One to encrypt, and one to decrypt (i.e. "undo" the encryption algorithm). For these two programs, you may assume that the input will be 4-digit numbers each time (no error-checking of inputs required).

Sample Outputs

Sample user input is underlined.

Sample output for 2.32

  Programming Exercise 2.32 'Digits'
  Input a 5-digit number: 1234
  * Not 5 digits, try again.
  Input a 5-digit number: 123456
  * Not 5 digits, try again.
  Input a 5-digit number: 39485

  Output:
  3   9   4   8   5

Sample output for 4.31 (Encrypt)

  Please enter a four-digit integer: 1234

  1234 encrypted --> 0189

Sample output for 4.31 (Decrypt)

  Please enter a four-digit integer: 0189

  0189 decrypted --> 1234

Sample output for Numbers exercise

  Numbers Exercise
  Input integer (0 to stop) 2
  Input integer (0 to stop) 4
  Input integer (0 to stop) -1
  Input integer (0 to stop) -5
  Input integer (0 to stop) 8
  Input integer (0 to stop) 0
  # of positives = 3
  # of negatives = 2
  Total = 8
  Average = 1.6


Compiling

Remember that the compile command is "javac", at the unix command prompt. Compile your code on program.cs.fsu.edu, and then run your programs with the "java" command.

Example:

   javac Numbers.java		// to compile
   java Numbers			// to run the program

Submitting:

To submit your assignment, you should pack up your source code files with the "tar" utility first. To do this, use the following command in the directory with your source code (this assumes the correct filenames as listed above):
   tar cvf hw1.tar Ch2_32.java Ch4_31_Encrypt.java Ch4_31_Decrypt.java Numbers.java
BEFORE YOU DO THIS -- BACK UP YOUR FILES. Make sure you do not leave out the "hw1.tar" (the target file this command will create), or you will end up overwriting one of your code files.

Alternately, if you make sure that the ONLY .java files in the currect directory are these four to submit (i.e. put all your assignment files in a folder for this assignment), you can use a unix wild-card shortcut in this command:

  tar cvf hw1.tar *.java
The above version will pack ALL .java files from the current directory into the file "hw1.tar". You should see the filenames list as they are "packed" into the file, in either case. Sample output when I run the command:
myers@diablo>tar cvf hw1.tar *.java
a Ch2_32.java 3K
a Ch4_31_Encrypt.java 2K
a Ch4_31_Decrypt.java 2K
a Numbers.java 3K
After you have packed up the files (they are now in the file called "hw1.tar"), e-mail this file as an attachment to "myers@cs.fsu.edu". The subject of your e-mail should be HW1-SUBMIT. Make sure you put your name and section number in the body of your e-mail.

If you don't know how to use the e-mail on your CS account, then you can FTP the "hw1.tar" file to your home computer (through the SSH file transfer feature) and e-mail from there.