CS 112
Spring 2023

Old version

This is the CS 112 site as it appeared on May 12, 2023.

Completing PS 4: Problem 4 without your own Card class

Overview

In PS 4: Problem 4, we’ve asked you to use the Card class that you wrote for Problem Set 3.

If you weren’t able to complete your own Card class, this page explains how you can use a compiled version of our Card class in your implementation of Blackjack.

Note: If you have a working Card class, there is no need to use our version, even if you are concerned that your Card class may have minor issues. We will be using our Card class when testing the code that you are writing for PS 4.

Downloading and installing a compiled version of our Card class

  1. If you haven’t already done so, create a ps4 folder for your work on this assignment, and download the starter files for this problem into that folder.

  2. Create a subfolder called lib within your ps4 folder.

  3. Download the following file into that new lib folder:
    Card.jar

    Make sure to put this file in the lib subfolder of your ps4 folder. If your browser doesn’t allow you to specify where a file should be saved, try right-clicking on its link above and choosing Save as... or Save link as..., which should produce a dialog box that allows you to choose the correct folder for the file.

    Note that only Card.jar should go in the lib subfolder. All of the other files for this problem should go in your ps4 folder.

  4. In VS Code, select the File->Open Folder or File->Open menu option, and use the resulting dialog box to find and open your ps4 folder. (Note: You must open the folder; it is not sufficient to simply open the file.)

    The name of the folder should appear in the Explorer pane on the left-hand side of the VS Code window, along with the names of the starter files Blackjack.java and Deck.java.

    In addition, you should see the name of the lib subfolder that your created above. If you click on the name lib, you should see that Card.jar is inside that subfolder.

    (Note: Because Card.jar is a compiled version of our Card class, clicking on the name of the file will not show you its contents.)

Running and testing your code without a random seed

If you install our Card.jar file in the way that we have outlined above, you should still be able to run the program by highlighting Blackjack.java in the list of files before using F5 to run the program. Another option is to right-click on the name of the Blackjack.java file in the Explorer pane and choose Run or Run Java.

Running and testing your code with a random seed

If you install our Card.jar file, the process of testing your program using a random seed will require that you enter different Terminal commands than the ones that we provide in the assignment.

Here are the revised procedures:

  1. As needed, open your ps4 folder by using the File->Open Folder or File->Open menu option in VS Code. (Note: You must open the folder; it is not sufficient to simply open the file.)

  2. If you don’t already have a Terminal pane at the bottom of the VS Code window, use the Terminal->New Terminal menu option to open one.

  3. Enter the following command from the Terminal to compile your code:

    javac -cp 'lib/*' *.java
    

    If executing this command produces error messages describing bugs in your code, fix them, save the file(s) in VS Code, and try again. Repeat this process until your code compiles without any error messages.

  4. Enter the following command from the Terminal to run your code with a random seed:

    • on Windows:

      java -cp 'lib/*;.' Blackjack seed
      

      where you replace seed with an integer.

    • on macOS or Linux:

      java -cp 'lib/*:.' Blackjack seed
      

      where you replace seed with an integer.

    Note: The two commands are almost identical, but in the Windows version there is a semi-colon (;) before the period (‘.’), whereas the macOS/Linux version uses a colon (:).

  5. If you make any changes to your code, make sure to:

    • Save the changed file(s) in VS Code.

    • Recompile your code by executing the command from step 3 before you attempt to rerun the program.