CS 111: Fundamentals of Programming 1
Lab 9
Goals
To work with
- Multiple class projects, constructors, mutators, accessors
- Writing your own classes
- More features of BlueJay
Main Goal
For Lab 8 you developed a program to play Blackjack. To do this, you made use of three classes, Card, Player
and Dealer, that I provided you. This week you are to develop those classes yourself. You will continue to use
your BlackjackInterface class from last week. Be sure to follow the specifications exactly. You should not have
to make any changes to BlackjackInterface. In fact, I may well substitute my BlackjackInterface class when
testing your classes.
Step 1 - Make a copy of your Lab8 folder and name it Lab9.
Step 2 - Open BlueJay and open the Blackjack project in Lab9.
Step 3 - Remove the Card class.
Right click on the Card class icon and take "remove".
Step 4. Create a new Card class - click on new class button.
You are to write the code for the Card class. Instances of this class should have
- A private instance variable of type int and called points. This will hold the point value of the card
in range 1 to 10 representing two possible values of an ace, etc.
- A private method, randomInt as before.
- A constructor with no parameters that initializes the points value randomly to 1-10. To be more realistic,
you should have a 10 be four times as likely to occur.
- A public accessor, getPoints, to obtain the point value of the card.
- A public toString method
- Nothing more.
Step 5 - Test the Card class
Once you have compiled the card class, right click on its icon and execute its constructor method to create
a Card object. Now right click on the object's icon and execute its getPoints method to see the value it has. Repeat
this with a couple more Card objects.
Step 6 - Test the Card class with your BlackjackInterface program
Step 7 - Remove Player class and create a new one.
You are to write code for the Player class. Instances of this class represent players for a simple version of
Blackjack. They should have
- A private instance variable of type int called total. This represents the total points in the hand.
This is initialized to 0. Aces count as 11 unless this puts the total over 21.
- A private instance variable of type boolean called soft. If this variable is true, that means the hand
holds an ace that is being counted as an 11. This is initialized to false.
- A constructor.
- An accessor getTotal that returns the total points the player has.
- A mutator, called setTotal, to apply a new card value to total. This uses the card as parameter, and considers
the old value of total and the value of soft. Here you should think carefully about all of the cases that could
occur and what should happen with total and soft as a result.
- A toString method
- Nothing more
Step 8. Test the Player class with Bluejay objects and your BlackjackInterface program.
Here you should use Card objects as well.
Step 9. Remove the Dealer class and create a new class called Dealer
The dealer will be consider as a special player; so the Dealer class should be a subclass of Player. Instances
of this class should have, in addition to the properties of Player,
- An accessor method, getCard, that generates and returns a Card object.
Step 10. Test the Dealer class with Bluejay objects and your BlackjackInterface program.
Here you should use Card and Player objects as well.
Step 11. Turn in your work.
When you have completed all work on this lab, you should turn in a print out for each of your classes. Be sure
to adhere closely to specifications given. Also adhere to points of programming style. Points will be deducted
for poor choice of variable names, poor indentation and placement of braces, lack of pre and post conditions, etc.
You should also copy your Lab9 folder into your turnin folder.
Be sure to follow the honor code specifications on the syllabus.