CSCI 201 Fall 2001

Assignment 1: Program 1

In this program you will learn to read strings from the keyboard and write them to the monitor. Write a program that asks the user to enter the first name of a friend or relative, a favorite color, a favorite food, and a favorite animal, then prints the following lines with the user's input replacing the items in italics:

  I had a dream that name ate a color animal
  and said that it tasted like food!
For example, if the user entered Jake for the person's name, blue for the color, hamburger for the food, and dog for the animal, the output would be:
  I had a dream that Jake ate a blue dog
  and said that it tasted like hamburger!
You should use the Keyboard class (provided by the authors' of your text) to make the job of reading strings from the keyboard easy. To use this class, follow these brief instructions:
  1. Create a project folder for this program using JCreator as described in lab 2. You may choose any name for the project folder, but the java file must be named Silly.
  2. In JCreator, close the workspace for the project created in step 1.
  3. Download the java source code for the Keyboard class using this link, and store it in the project folder created in step 1.
  4. In JCreator, open the workspace for the project, and select Add Files... from the Project menu option on the JCreator tool bar.
  5. In the pop-up window that appears, select or type Keyboard.java and select Open.
  6. The Keyboard class is now included in your project. To use the class in your program you simply need to include the following line of code at the start of your program:
      import cs1.Keyboard;
    
    Remember that capitilization is important. There are examples of programs that use the Keyboard class in Figures 2.10, 2.11, and 2.12 of your text.

    Assignment 1: Program 2

    In this program you will learn to use integer division and the modulus (or, as the book calls it the remainder) operator. You should write a program that reads in a four digit number (like 1998) and that outputs the numbers one digit per line, like so:
      1
      9
      9
      8
    
    Your prompt should tell the user to enter a four-digit number and you can then assume that the user follows directions. Again, you will need to use the Keyboard class to make the job of reading the number easy. Follow the instructions given above for using that class in this program, with one exception. In step 1, the name of the java source code file for this program must be Digits.

    Hint: If a variable named number initially stores the value 1998:

    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., Silly.java, and Digits.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, here is a quick refresher.