Design/project09.txt
.edu.INSTITUTION.USERNAME.hotj.project09
.edu.INSTITUTION.USERNAME.hotj.project09
package.Your instructor will assign you one of the problems below. To solve your problem, write a program that reads the necessary information to compute and output the indicated values, as efficiently as possible. Following the pattern in the lab exercise, first, design using OCD. Then code your design in Java using stepwise translation. Test your program thoroughly.
When executing your program to hand in as part of the project, a JUnit test case should test each method at least five times, but the test case itself needs to be executed just once. A driver program should be run at least five times with different inputs each time.
Project #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". 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
Algorithm
- Let
values
be a sequence with at least one value.- Let
n
be the number of values in the sequence.- Initialize
gMean
to 1.- For each
value i
:
SetgMean
to be the product ofgMean
andvalue i
.
End for.- Return the
n
th root ofgMean
.Write a method for the
GradeBook
class that computes the geometric mean of the grades, using the array of students asvalues
. Add this computation to the output. Also be sure to add a test method to test this new computation.
Project #9.2: Implement a
Histogram
class that records a histogram of integer values. A histogram counts the number of times each of the values occur.Usually we see histograms as a graph:
74: *** 75: ***** 76: ****** 77: 78: **This graph of the histogram indicates that the value 74 was seen three times, the value 75 was seen five times, 76 seen six times, 77 seen zero times, and 78 seen two times. All other values were never seen. (Note that these values could be temperatures, test scores, ages, or some other kind of data; the histogram doesn't care!)
Write a
Histogram
class that keeps track of the number of times that particular values occur in a data set. (Do not store the graph! Store the counts!) The constructor for the class should receive minimum and maximum values for the data range; this makes saving the counts and creating a graph a bit easier.Write a
Histogram#toString()
method that displays the raw data; for example,74:3 75:5 76:6 78:2Then write
Histogram#toGraph()
to return a graph of the histogram as aString
.Both methods should include only the values between the minimum and maximum (inclusive).
Histogram#toString()
should not include values with a 0 count.Write test methods for both of these methods.
Project #9.3: 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 aPlayingCard
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 ofPlayingCard
values. YourDeckOfCards
class should provide operations to construct, shuffle, and take the top card. The class constructor should initialize theDeckOfCards
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 that plays a simple card game (i.e., blackjack, go fish, etc.) against a human opponent.
Turn the following things:
Lab Home Page | Prelab Questions | Lab Exercise | Homework Projects