Gettysburg College

CS 111
Computer Science I

Fall 2025

Assignment 6

Due: Thu, Oct 9, by 11:59pm

General Description

The goal of this assignment is to create an app for the popular BlackJack game. In BlackJack players repeatedly draw cards aiming to get as close to 21 as possible.

The focus of this assignment is on for loops and array processing.

Preliminaries (New DrJava)

Download the new version of DrJava:

This DrJava version includes:

Preliminaries

Start DrJava and create a new project named BlackJackApp in folder cs111/hw . See the Readings List notes on how to create a new project.

For this app the phone should be put in landscape/tablet orientation.

Card Images

Download the file cards.zip and extract it in the app folder BlackJackApp/res/raw/

cards.zip

Make sure only the ".png" files end up in the required folder without the ".zip" file.

The cards will be represented as integers, either as RS or RRS:
  • last digit S is 1, 2, 3, 4 and represents the suit:

    1=♣, 2=, 3=, 4=♠

  • leading digits R or RR are 1, 2, 3, ..., 13 and represent the rank:

    1=aces, 2=twos, ..., 10=tens, 11=jacks, 12=queens, 13=kings

  • see the table for the names of the card images
    note that card0.png is the image for the back face

Back card0.png
Aces card11.png card12.png card13.png card14.png
2s card21.png card22.png card23.png card24.png
3s card31.png card32.png card33.png card34.png
. . .
Queens card121.png card122.png card123.png card124.png
Kings card131.png card132.png card133.png card134.png

  • 131 is king of ♣: rank 13 and suit 1
  • 24 is two of ♠: rank 2 and suit 4
  • 102 is ten of : rank 10 and suit 2

Game Description

Here is a summary of how the app works:

The app cycles through the (active) players waiting for taps:

The game terminates when all players are inactive (i.e. some lost, some chose not to draw any more cards, some got 21).

Determining the winners is a bit complicated, so at the end of the game it is sufficient to display a generic game-over message.

General Expectations

Required Methods

As part of your solution you are asked to implement and utilize the following methods:

Putting it all together

Make sure you implement the above methods first and test them thoroughly. Submit your test cases as a commented section in your program.

It is best to work in stages. Some suggestions are given below.

Here is a visualization of the game for 4 players along with the various variables (shown in bold) that will be used and updated during the game. These are described also in method playGame:

Note: When you create an array, Java will put the blank value by default, i.e. 0 for int/double arrays and false for boolean arrays. These are often convenient starting points.

isInactive:   | false | false | false | false |      nobody is inactive initially (Java puts false by default)
total points: |   0   |   0   |   0   |   0   |      nobody has points initially
last card:    |   0   |   0   |   0   |   0   |      nobody has a card initially (Java puts 0 by default)
              ---------------------------------    
                  0       1       2       3          player indices
                  ^
                  |
              curPlayer -- keeps track of whose turn it is; tells us
                           which cell in the three arrays to update


deck:       | 11 | 12 | 13 | 14 | ... ... | 131 | 132 | 133 | 134 |
                                                               ^
                                                               |
                                                         dealCardIndex -- the index of the card to deal next:
                                                                          * starts at the end of the deck
                                                                          * it is the index, not the card

Here is a possible starting point for the app.

void playGame(int n)
{
    // 0. show dealer skills: do later after "Dealer Skills"

    // 1. create a deck and shuffle it: (leave shuffle for later, see stages)


    // 2. create three arrays to keep track of the
    //    information about each player in the game:
    //    * array of booleans that tracks the status of each player (active or inactive)
    //    * array of integers that tracks total points of each player (initially 0)
    //    * array of integers that tracks last card drawn by player (initially 0)

    boolean[] isInactive = new boolean[n];     // Java will set all n cells to false by default
                                               // i.e. nobody is inactive / everybody is active

    // similarly, create the other two arrays for points and last card drawn
    // note that Java will put 0 by default in each cell when array is created


    // 3. create two integers to keep track of (see above):
    //    * index of current player: cycle among 0..n-1 (inclusive)     
    //    * index of next card to deal from the deck

    as long as there are active players:
    {  
         //...........................................................
	 //... the rest of the code goes here:
         //... * clear,
         //      draw scene,
         //      wait for input,
         //      update player details, i.e. update the three arrays above
         //...   (only wait for input and update if player is not inactive)
	 //...........................................................


         // this Java line will increase the current index by 1 to move to the next player,
         // but it will also automatically go back to 0 after the last, i.e. (n-1)th player

         curPlayer = (curPlayer + 1) % n;   // must be last line in loop
    }

    // ... 
}

Stage 1

Ignore the active/inactive component and make the loop condition:

while ( curPlayer < 100 )

On each touch give a card to the current player regardless of whether the player has 21 or over. The game will go on forever, but you should see the latest cards given to the players drawn on the screen and the deck shrinking.

Next increase the points of the players by the value of the card they were given. You should now see the points changing on each round.

Stage 2

Deactivate players who were given a card that makes them inactive based on the rules above. You should see the players in different colors.

Fix the loop condition so that the game stops when there no active players.

Stage 3

Deactivate current player if number of taps is 2. Ensure that card is given only if current player is active.

Stage 4

Compute the full deck and shuffle it.

Dealer Skills

Create the following methods that show the dealer card skills (and your programming skills). Make sure to test each method with (a) the empty array; (b) one-element array; (c) multi-element arrays.


What to turn in

Turn in the Java code for the app in the Assignment 6 dropbox: