CSE 283 Introduction to Object Oriented Design
Barbara Nostrand, Ph.D.
CSE 283 Labs
Lab 9: Projects
Your instructor will tell you which one of the following projects to do.
9.1. When people talk about an average value, most often they are referring to the arithmetic mean as we computed in the exercise. There are, however, other "measures of central tendency" that are in use. For example, the geometric mean of a sequence of n values is the n'th root of the product of all the values. A simple algorithm to compute the geometric mean of a sequence of values is
a. Let seq be a sequence with at least one value. b. Let n be the number of values in the sequence. c. Initialize gMean to 1. d. For each valuei in the sequence Multiply gMean by valuei(1/n) e. Return gMean.
Write a method that, given an array of numbers, computes the geometric mean of those numbers. Then use this method to write a program that, given the name of a file containing an arbitrary sequence of numbers, computes and displays the geometric mean of that sequence.
9.2. A certain on-line testing program records student exam results in a text file, each line of which has the form:
Write a program that (using an array) analyzes student performance on an exam using the information from such a file. The program should input the name of the text file, and then display the worst score, the best score, the average score, the standard deviation, and a histogram -- a bar graph indicating the frequency with which a given score occurred. For example, if three people scored 74, five people scored 75, six people scored 76, no one scored 77 and two people scored 78, then that portion of the histogram should appear as:
74: *** 75: ***** 76: ****** 77: 78: **
Entries below the worst or above the best should not be displayed.
9.3. Each year, the well-known meteorologist Dr. H. Tu Oh creates a file containing the year's 12 monthly precipitation totals (e.g., rain1997.data). Write a program that, given the names of two of these files, will create a file containing an easy-to-read analysis comparing the two sets of readings, including which of the two years was the wettest (and by how much), the average monthly precipitation for each year, and the wettest and driest months in each year.
9.4. Write a program called Analyze that, given the name of a text file, reads that file and counts the number of occurrences of each alphabetic letter in the file. Your program should use an array of length 26 to count the occurrences of the 26 alphabetic letters, and treat upper and lower-case instances of a letter as the same letter. Once the file is read, your program should display a histogram for each of the 26 modern English letters. For extra credit, produce a list of the letters sorted by frequency.There are several possible methods for detecting the end of a file. One involves catching the EOFException. Another depends on a special return value when you attempt to read past the end of the file. This method is used in a demonstration program List.java which displays the contents of a file on the screen.
Run your program on several large text files (e.g., save on-line help files or manuals and use them as inputs to your program). Study the results looking for patterns; then write a paragraph in a file called Analysis.doc explaining how your observations could be useful to a person
9.5. A playing card has two attributes, its rank (e.g., 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A) and its suit (e.g., clubs, diamonds, hearts, spades). Design and build a PlayingCard class that models a playing card. Your class should provide operations to construct, input, output, compare, and access the attributes of a PlayingCard object.
A deck of cards is simply a sequence of cards. Design and create a class DeckOfCards that represents such objects by using an array to store a sequence of PlayingCard values. Your DeckOfCards class should provide operations to construct, shuffle, and take the top card. The class constructor should initialize the DeckOfCards as a new deck of 52 cards (i.e., 2-clubs, 3-clubs, ..., A-clubs, 2-diamonds, ..., A-diamonds, 2-hearts, ..., A-hearts, 2-spades, ..., A-spades). The shuffle operation should rearrange the cards in a deck in random order. The final operation should remove the top card from the deck, and return that card.
To test your classes, write a program called Blackjack that plays blackjack against a human opponent. The computer will take the role of the dealer. In black Jack, the cards have the following values:
Don't forget to clean up your directory when you are all finished...
Last modified: 2007 OCT 30