Homework 1, Due Wednesday, 9/10 in class


  1. Read, understand, and execute the program: RandomTest.java.
    1. Run this program 5 times and attach the output obtained from these 5 runs.
    2. Describe in 2-3 sentences what the program does.
    3. The program can be simplified by using the method nextInt rather than the method nextDouble. Make this change and rerun the program 5 times. Attach the new output. You might want to consult documentation for the Random class.

    What to submit: (i) Printout of output from 5 runs of the original program, (ii) a 2-3 sentence write-up for the second part of the problme, and (iii) Printout of output from 5 runs of the modified program.

  2. The file words.dat contains a list of all valid 5-letter English words. There are 5757 of these. Write a program that reads these words and prints out the number of words that start with the letter "a", the number of words that start with "b", the number of words that start with "c", etc. Your output should be easily readable - maybe in tabular format.

    To read from the file, you can start by building a BufferedReader object as follows.

              BufferedReader in = new BufferedReader(new FileReader("words.dat"));
    

    Then you can use methods from the BufferedReader class (e.g., readLine) to read from the file. You might want to consult documentation for the BufferedReader class.

    What to submit: Call your program wordCount. So you should be submitting a file called wordCount.java that defines a class called wordCount. You should also submit a printout of the output of this program.

  3. Add a method to the RecordDB class called rangeSearch that takes as arguments a salary range and returns records of all employees whose salaries are in the specified range. More precisely, the method should have the following header:
    	Record[] rangeSearch(double pay1, double pay2)
    
    This method returns an array of records corresponding to all employees whose salaries are between pay1 and pay2 (inclusive of pay1 and pay2). The size of this array should be exactly equal to the number of employees whose salaries are in the specified range.

    What to submit: A printout of just the new method rangeSearch.

  4. Testing your code is an important skill and you should, in general, be thinking carefully about testing for any piece of code you write. This problem asks you to develop a "test" for the rangeSearch method you wrote for the previous problem. Write a program called RangeSearchTest in which you (i) insert a bunch of appropriately chosen records into a RecordDB object, (ii) repeatedly perform rangeSearch operations on this RecordDB object, and (iii) output the results from each call to the rangeSearch method. Then verify by hand that the output is completely correct.

    Think of various different situations that might affect the performance of rangeSearch and test these separately. For example, you should test for the situation in which there is no employee in the selected range. Another example, is the situation in which the entire set of employees is in the selected range. There are several other distinct situations that I can think of.

    Write a paragraph listing all of the situations that you tested for.

    What to submit: (i) A printout of the program RangeSearchTest, (ii) a printout of the output of RangeSearchTest, and (iii) a printout of your paragraph long write-up enumerating all the cases you tested.