Program #4
Extra-credit due date: Friday, March 2, 2:00 pm
(for 5 pts extra credit)
"Regular" due date extended to: Monday, March 5, 2:00
pm
Purpose
The objectives for this assignment are to:
-
Create an externally defined class
-
Input from HTML
-
Use Java AWT and/or Swing features (you choose one or both as appropriate)
-
To write a class that will be used to create objects in another class
-
To promote object-oriented-ness in your programs.
Description
You will be writing an applet that responds to input from an HTML and creates
poker chips of different values. The user will have a pile for each
color of chips (red blue and green), and there will a pile at the center
oject based on this input. Under each user pile there will a total
value of the chips in the pile and a button "ante" to move a chip into
the center pile. There will also be two buttons, "Computer Wins"
and "I win". If the "Computer Wins" button is pushed the coins should
be removed from the middle pile and "no longer exist". If "I win"
button is pushed then coins should be moved back to the correct pile (red,
blue, or green). The red chips will have the value 100,
blue 500, and the green chips will have a random value between 0 and 1000
(determined using a random number generator). The number of each
type of chip will be read from the HTML file. See screen
shot for example of what the board might look like.
Assignment
Write an Applet that reads parameters from an HTML file. These parameters
are the number of blue, red and green chips the player will start out with.
Inside the html file name these parameters "nRedChips", "nBlueChips", "nGreenChips".
Lay out the chips so the user is able to see how many chips they have.
You can imagine looking down at the "table" with the chips on it.
The number of chips should be displayed below each pile, including the
middle pile. Besides each chip having a color it should also have
its value written on it. This will be especially important for the
green chips since they do not have a predetermined value.
Implement the buttons as described above. Determine what both
the Pile should know about itself, and the chips. So, for example,
a pile should know how many chips it has in it, and the total value of
those chips. But, since a chip will know its own color, middle pile
need not know the color of the chips it is holding. These things
should help you to determine what instance variables each class needs.
A few hints
-
Use Math.random() to generate random numbers for the face value of the
green chips.
-
Since the number of chips for each color stored in the html file is a string
of digits (e.g., PARAM NAME = "RED" VALUE = "5") , you might find the Integer.parseInt(String
x) function helpful. This function returns a primitive int value.
Details
We will also be looking for the following style types of things in your
program (these should be in every program!):
-
A comment at the beginning of the file describing the general purpose of
the file
-
Comments within the code (not on every line), more for things that a bit
more complicated -- remember that you want to know what this program does
when you go back and look at it a few years later.
-
Each method should have a comment (generally before the method) that describes
the purpose of the method.
-
Choose your variables so you and others will understand their purpose (for
example int x is generally not a good name, it does not tell much
about what x does; counter would be better if you are using it as a counter
somewhere in the program).
-
Use Indentation and spacing for greatest readability (this is very important
for understandability of code!).
Turn In
Turn in electronically by 2:00pm 3/2/2001:
-
Your PokerChip.java file
-
Your Pile.java file
-
Your Applet Java program which must be named PokerChipsApplet.java
-
Your HTML file which must be named PokerChipsApplet.html