Homework 8 for Computer Science 125

Introduction to Computer Science

Boise State University, Spring 1999


This homework is due by 9 p.m., Friday, 23 April 1999. See the directions in Homework 1 to electronically submit homework.

Warm-up and Practice Problems

These are not be turned in. They are to help you understand the material, and some will appear on exams.

Graded Problems

You must comment your code (see book for examples).
You must include comments for all functions, following the javadoc format. See CCJ, p 183-185 for more details.

    P23. (NPR Puzzle) Write a program that takes the name of a word file and a desired score. These input parameters can be given at the command line:
     > java Program23 wordFile 225 
    where the first argument is the name of the file and the second is the desired score. If the user does not provide arguments when calling the program, that is, they invoke the program with the command:
     > java Program23 
    prompt the user for the the name of the file, then for the desired score.

    The program then prints out all words with that score from that given file. To assign a score to word, first assign a number to each letter: 1 to A, 2 to B, 3 to C, etc. Then, the score of the word is the product of the numbers assigned to the letters. For example, the score of cab is 3*1*2 = 6.

    For example, if the file wordy contains:
    cab
    bat
    batty
    cat
    cats
    mat
    mate
    gate
    agate
    and the user types in the command:

     > java Program23 wordy 700 
    The program prints:
     The following words have a score of 700:
    	gate
    	agate 

    Submit this as program 23 using the electronic submission. Please call the file (and the class) Program23.

    Hint: To assign a number to each letter, use the method indexOf on the string "*ABCDEFGHIJKLMNOPQRSTUVWXYZ". For example,

    	"*ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf("C")
    	
    is 3. See Section 11.6, p 468 for an example of using indexOf.

    (See NPR's Weekend Edition for a related puzzler (28 March 1999)).

    P24. (GPA Calculator) In plain java, write a GPA calculator that allows the user to enter the grade and the credit hour of their courses, and then calculates their GPA. The calculator should include a clear button that clears all previously entered scores, a choice button for the letter grade, a choice for the number of credit hours, and a submit button that records their entry, displays the current GPA, and resets the choice buttons. For example:

    Follow the javadoc comments for this applet when setting up your program.

    Submit this as program 24 using the electronic submission. Please call the file (and the class) Program24. Include an HTML file called Program24.html to display your applet.

    Hints:

    P25. (Merge sort, using sortedMerge) Write a program that:
    1. Asks the user for the number of integers in their list.
    2. Reads in those elements.
    3. Calls a function called sort that sorts the list.
    4. Prints out the list of numbers.
    The sort function should split the list of numbers into two lists of about the same length, sort each of these lists, and then merge the lists together, using mergedSorted (P21 from Homework 7). Submit this as program 25 using the electronic submission. Please call the file (and the class) Program25.