CIS 068 / 2: Lab - Assignment #2: High or Low

Program a simple card game, called "High Or Low":
Assume a deck of 7 cards given, the cards are numbered from 1 to 7. After shuffling, the uppermost card of the deck is presented to the player, who now has to decide, if the next card will be higher or lower in value. if he guessed right, the game is continued, i.e. he again has to guess, if the third card is higher/lower than the second one a.s.o.
The player wins, if there are no more cards left to uncover. He loses, if he precalculated incorrectly.

A typical output of the game would be:

Welcome to High Or Low.
Shuffling...
Uncovered cards: 3 --> (h)igh or (l)ow ? h
uncovered cards: 3 5 --> you were right ! 5 to go. (h)igh or (l)ow ? l
uncovered cards: 3 5 1 --> you were right ! 4 to go. (h)igh or (l)ow ? l
uncovered cards: 3 5 1 2 --> sorry, you were wrong ! You lost this game.
Bye.


Requirements, as developed in the Wednesday class:

The use-cases (Initial, Player's Decision, Lost, GoOn) led to the following methods:
class HighOrLow:

class Deck:

...of course, we were in an early phase of detailed analysis, maybe it will show, that there are some methods missing or must be adjusted...


algorithm for shuffling:
the most natural data structure for the deck is an array of int. So let's define:
int[] theDeck = {1,2,3,4,5,6,7};

one typical algorithm to shuffle would be:
do 50 times:
randomly select 2 cards and swap them
end

some help:
you get a random number myRandomNumber between [0..6] (zero and six included) by:
int myRandomNumber = (int)(Math.floor(Math.rand() * 7));

a useful method:(java.io.* must be imported !)

/* requestUserInput
// read keyboard,
// return true if input was 'h'
// return false if input was 'l'
*/

private boolean requestUserInput()
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String line = "";
while (line.length() != 1 || (line.charAt(0) != 'h' && line.charAt(0) != 'l')) {
System.out.print("(h)igh or (l)ow ? ");
try{
line = in.readLine();
}catch(Exception e)
{}
}
return (line.charAt(0) == 'h');
}


We will discover more problems in the friday-lab, maybe some more help will be added here. So stay online !