##### Child pages
• CS 231 Project 1
Go to start of banner

# Abstract

This project helped introduce us to Java through creating a game of blackjack. Our objective was to create a simulated game of blackjack that would record the number of times the house won, a player won, or there was a push. With the need to create a Card, Hand, Deck, Blackjack, and Simulation files we became more familiar with the object-orientated nature of Java. The emphasis on ArrayLists class also allowed us to become familiarized with the initialization of objects. Overall this project strengthened our basic java skills. It also showed how the house is always favored in blackjack and that gambling is bad!!!!

# Solutions

There were many different interesting hurdles along the way that needed solutions. Shuffling the deck and winning the game are the most interesting solutions in this project.

For shuffling, within a for loop with an index "i", I had the simulation choose a pseudorandom "x" number between 1 and 52. I then had it store the card value x  in a temporary variable "a". It then moved an into the i index in the deck. Meanwhile, I took the i value and moved it to where the x card value used to be.

The winning section is slightly more concise. It was either true or false that the player bust. If that's true then the player loses. However, if it was false then next I had it check if the house bust. If the house was true and busted then the player would claim the win. If neither bust, both false, then I crosschecked the total points in each hand. Whoever had more was the winner. If it was a tie then it was a push. The house has the advantage here because the player had to play their entire hand first, so the player could bust before the house really participated in the game.

# Questions

Are 1000 games sufficient to provide an accurate estimate of the win percentage for the player and dealer? What are those percentages?

• It's sufficient enough to provide a trustworthy estimate of the win percentage. For the most part, player win% hovered around 40%, house at 50%, and push at 10%.

What is the number of games the simulation has to play in order for the dealer's win percentage always to be above the player's win percentage over ten runs of the simulation?

• I personally found this number to be 8 trials.

# Printouts

Here are the results of my three trials.

Here is the outcome of my 1000 trials.

# Conclusion

This project taught me many things. It made the object-oriented coding that I learned with python more important. I learned much of the syntax that was different. I think what stood out the most was the difference between the static nature of java and the dynamic nature of python. I had to be much more precise and meaningful with my code, but there were benefits. The compiler allowed for my simulation to run in a fraction of the time it would take to run if I had coded it through python. Overall this project got me to a point where I feel comfortable diving deeper into Java.

# Extension

What started out at a plan for a smaller extension ended up taking up much more time and taught me a lot more than I expected. I wanted to involve console inputs to allow me to alter the number of trials I had in my simulation. However, in java, it was not as simple as It was in python with arguments. After some searching, I found that there were three primary means of allowing console inputs. There was the Buffer Reader class, Scanner class, and Console class. I ended up opting for the Scanner class as it was the most applicable to my situation. After some reading of the documentation, I figured out how to implement it. This implementation allowed me to alter the number of trials from my console, making it easier to compare different sample sizes.

here is an example of how my extension helped.

# Acknowledgments

I'd like to thank my peers for working with me,

Deka Popov

Ben Lawlor

Erik Cohen