Java

OOP GUIDE / WORK

 

CARD CLASS 3

 

Topics

  • Using objects

 

 

TASK – PART 1 – CARD CLASS SETUP

In this task, we will create a few different programs that make us of the Card class.

 

Start by copying and pasting the Card class that was created in Card Class 2 (if you do not already have it).  Go to the Card Class 2 Solutions to get it.

 

 

TASK – PART 2 – RED OR BLACK CARD (CARD PROGRAM 01)

 

In the class CardProgram01, write a program that creates a random card.  It then outputs either “Red card” or “Black card”.

 

Remember that a heart and a diamond is red while a spade and a club is black.

 

 

TASK – PART 3 – CARD HAND & TOTAL (CARD PROGRAM 02)

 

In the class CardProgram02, write a program that creates five random cards.  These five cards represent a hand of cards. 

 

The program then outputs all five cards on a single line.  Finally, the program totals up the value of all cards and outputs the hand’s total to screen.

 

Note: A hand containing a 2, 5, J, A and 4 would have a total of 23.

 

 

TASK – PART 4 – WAR (CARD PROGRAM 03)

 

In the class CardProgram03, write a program that will simulate a single round of the simple card game War. 

 

Very simply, player1 will get a random card and player 2 will get a random card.  Both cards will be displayed on the screen. 

 

Then the winner is the one that with the card that is the highest value.

 

 

TASK – PART 4 – BLACKJACK (CARD PROGRAM 04)

 

In the class CardProgram04, write a program that will simulate a round of the card game Black Jack. 

 

This game is similar to War in the sense that there are two players.  The first player is a human and the second player is the dealer.

 

The first player starts with two cards and can request more cards one at a time.  The player’s goal is to get to a total as close as possible to 21 without going over.  If the player goes over 21, they lose immediately.  Once the player is happy with their card total, it is the dealer’s turn.

 

The dealer starts with two cards.  The dealer must continue taking a new card until their card total is greater than 16.  If the dealer exceeds 21, then player 1 wins.

 

If neither player exceeded 21, then the player with the highest total wins.  In the case of a tie, the dealer wins!  L

 

A few extra details:

  • All face cards have a value of 10.
  • Aces can count as either a 1 or an 11 (but you can omit this feature to keep things simple).


You should create a simple game that is similar to the rules explained above though you can alter some details if you wish.