Assignment #1 - Chapter 2 Exercises

Due: Wednesday, May 21

From chapter 2, do programming exercises 2.1, 2.5, 2.6, and 2.7 (these start on page 79)
Filenames should be

To do these exercises, you will need the following MyInput class that was used in lecture. This class can read in strings, integers, and doubles from the keyboard. Paste this class into each of your own program files.

// a class for reading various types from the keyboard (System.in) 
class MyInput
{
    public static String readString()
    {
        String string = "";
        java.io.BufferedReader bufferedReader = 
           new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
        try
        {
            string = bufferedReader.readLine();
        }
        catch (java.io.IOException ex)
        {
            throw new RuntimeException(ex);
        }
        return string;
    }

    public static int readInt()
    {
        return Integer.parseInt(readString());
    }

    public static double readDouble()
    {
        return Double.parseDouble(readString());
    }

    // test all the methods of this class
    public static void main(String[] args)
    {
        System.out.println("Testing 'readString()'");
        System.out.print("Input your string : ");
        System.out.println("Your string was '" + readString() + "'");
        System.out.println("\nTesting 'readInt()'");
        System.out.print("Input your int : ");
        System.out.println("Your int was '" + readInt() + "'");
        System.out.println("\nTesting 'readDouble()'");
        System.out.print("Input your double : ");
        System.out.println("Your double was '" + readDouble() + "'");
    }
}

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 Prob2_1.java
  java Prob2_1

Submitting:

Submit programs through the submission web page -- this is now linked from the course home page. You will need your submission password, which is being handed out in recitation class this week. If you miss recitation, then e-mail me ASAP to get your submission password, before this one is due. And please hang on to this password -- you will need it all term.