blackjack

How to add the values of two “Cards” in Java?

血红的双手。 提交于 2019-12-02 12:26:24
I am working on a project to simulate the first deal in a game of blackjack. So far, the program creates two cards of random rank (ACE to KING) and random suit. I am struggling with created a switch table or if-else ladder assign the added value of the two cards as a variable score. The code below represents conceptually what I am trying to do, I just want to know how to make it simpler. Thanks! public int Score() { int score = 0; if (card1.rank() == TWO && card2.rank() == TWO){ score = 4; } else if (card1.rank() == THREE && card2.rank() == TWO){ score = 5; } else if (card1.rank() == FOUR &&

OOP BlackJack Game (Creating Deck)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 04:55:41
问题 I am attempting to create an OOP friendly Java BlackJack game to progress my knowledge. I've hit a wall and I just don't know enough to see the problem. Was wondering if anyone could point out my problems. Additionally, after googling relevant topics about this I've found people time and time again saying using enums would be more beneficial, as a beginner would this be advised? Or should I stick with String arrays for the time being. Thank you. my code: public class BlackJack{ BlackJack() {

OOP BlackJack Game (Creating Deck)

我与影子孤独终老i 提交于 2019-12-02 00:06:46
I am attempting to create an OOP friendly Java BlackJack game to progress my knowledge. I've hit a wall and I just don't know enough to see the problem. Was wondering if anyone could point out my problems. Additionally, after googling relevant topics about this I've found people time and time again saying using enums would be more beneficial, as a beginner would this be advised? Or should I stick with String arrays for the time being. Thank you. my code: public class BlackJack{ BlackJack() { Deck deck = new Deck(); deck.createDeck(); System.out.println(deck.deckList); } public static void main

How can i fixTypeError: 'str' object is not callable?

∥☆過路亽.° 提交于 2019-12-01 14:44:06
Well i've seen this error occur to others aswell but i can't figure out were my mistake is. I get this: Traceback (most recent call last): File "C:\Users\Bill\Desktop\Finalizing_2.1(DEVELOPING).py", line 100, in <module> combined = list(zip(symbols,deck)) TypeError: 'str' object is not callable Here is my code: (Python 3.x) import random #shuffle import os#file deleting def shuffledDeck(deck):#shuffles ceck random.shuffle(deck) def dealCard(deck,participant):#deal cards , chooses between player and house with string z participant.append(deck.pop()) if z==1: print('\nYou got %s ' %("{} {}"

How can i fixTypeError: 'str' object is not callable?

只谈情不闲聊 提交于 2019-12-01 12:28:19
问题 Well i've seen this error occur to others aswell but i can't figure out were my mistake is. I get this: Traceback (most recent call last): File "C:\Users\Bill\Desktop\Finalizing_2.1(DEVELOPING).py", line 100, in <module> combined = list(zip(symbols,deck)) TypeError: 'str' object is not callable Here is my code: (Python 3.x) import random #shuffle import os#file deleting def shuffledDeck(deck):#shuffles ceck random.shuffle(deck) def dealCard(deck,participant):#deal cards , chooses between

Why am I getting this error? “bad operand types for binary operator '>'”

眉间皱痕 提交于 2019-12-01 09:41:59
问题 I would like to know what it causing the error of "bad operand types for binary operator '>'" down below I have the codes for both my Hand and Card classes. I've also specified the lines that are causing the error. Thanks for the help. This is for a BlackJack project. Hand Class import java.util.Vector; public class Hand { private Vector hand; // The cards in the hand. public Hand() { // Create a Hand object that is initially empty. hand = new Vector(); } public void clear() { // Discard all

Array for Blackjack cards, strings or integers?

╄→гoц情女王★ 提交于 2019-12-01 01:09:57
Having a look at related BlackJack questions, there is a confusion on what is better to use for the cards, either making an array of strings/items or integers. With my BlackJack game Aces are 11 only and 10, J, Q and K are all value 10, doesn't matter of the suit. What would make it easier for me to code the cards with, strings or integers? Visual Studio C# 2010, Windows form application A Card is an object, so make it its own class. An enum of Suit (Heart, Diamond, Club, Spade) and an enum for Rank (Ace, Jack, 10, etc., ordered accordingly for ease of comparison) should be used. You can

Convert an array into an ArrayList [duplicate]

China☆狼群 提交于 2019-11-29 21:11:06
This question already has an answer here: Create ArrayList from array 35 answers I'm having a lot of trouble turning an array into an ArrayList in Java. This is my array right now: Card[] hand = new Card[2]; "hand" holds an array of "Cards". How this would look like as an ArrayList ? twain249 As an ArrayList that line would be import java.util.ArrayList; ... ArrayList<Card> hand = new ArrayList<Card>(); To use the ArrayList you have do hand.get(i); //gets the element at position i hand.add(obj); //adds the obj to the end of the list hand.remove(i); //removes the element at position i hand.add

Is there an elegant way to deal with the Ace in Blackjack?

◇◆丶佛笑我妖孽 提交于 2019-11-27 23:36:07
My kiddo had a homework assignment to write Blackjack in Java. I helped him a little but for the most part he did it all himself and it actually plays pretty well. He even caught an error I didn't see in how it was calculating hand values. However, there is a snag that he hasn't dealt with and every solution I can think of is really complicated and way beyond what he's going to be able to easily code up with his still rudimentary Java skills. The Ace. In fact, not just one Ace, there's four of them and you could possibly get all four of them in a single hand. How do you elegantly deal with