MET CS 565 Spring 2004 - HW2 (Due Feb 17, 2004 ) 20 Points

Goals

Problem

We want to simulate two players playing at a casino. Each player walks into the casino with an initial amount they want to gamble. They can wage any amount as long as the wager is less than or equal to their remaining balance. Each slot machine has three slots, each slot will be populated with a random value between 1 and 9. The wins and losses are determined as follows:

 

Develop an applet with a simple GUI as shown to simulate the two players. First, write the class Player with the following behavior:

Now, develop the applet class with two Player objects. Please see the sample code how to get the Buttons working.  A play is simulated as follows: Call the randomValue() method of the corresponding player three times to get the three slot values. Then pass these and the wager amount to the play method of that player. Then update the label for the player by calling the toString() method of that player.

Click here to see the applet in action

Part 2

Extend the player class to create another class called PreferredPlayer. For this player, the rules will be as follows.

     So, you have to override the play method for this class. Also, override the toString method so that it concatenates the prefix "Pr:" to the super class's toString method.  Provide the constructor as above for this class and class the super's constructor in its body.

Now, develop another applet with a regular Player object and another a PreferredPlayer object.  Use polymorphism, i.e, you will be declaring the two variables as of type Player, but instantiating the latter with the PreferredPlayer constructor.

Click here to see the applet in action