Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I still haven\'t gotten any right answers for my question so I just wanted to as

ID: 3659363 • Letter: I

Question

I still haven't gotten any right answers for my question so I just wanted to ask one last time. Only answers that are right well get full stars. thanks. I need for the game to have everything using this coding implement a blackjack game. The code should include hit, stand, double, split, or surrender. The game is 10 rounds The instructions are: Implement a blackjack cards game with betting between 1 user and the computer (dealer). We will use a deck of playing cards with the following cards 2<3<...<10< diamonds < clubs < spades. At the beginning of the game, the user starts with $20 and can bet at most 2 dollars per game (i.e., the user can only bet $1 or $2). At the beginning of each round, the user places his bet in his "betting box". The user box is dealt an initial hand of two cards visible to the user. The computer/dealer's hand receives its first card face up, and its second card face down immediately (the hole card), which the computer does not reveal unless it makes the its hand a blackjack. The user's object is to win money by creating card totals which will turn out to be higher than the dealer's hand, but without exceeding 21 ("busting"/"breaking"). The user must choose whether to "hit" (take a card), "stand" (end their turn), "double" (double wager, take a single card and finish), "split" (if the two cards have the same value (i.e., rank, e.g., the player can split if he has 2 queens), separate them to make two hands) or "surrender" (give up a half-bet and retire from the game). Once the player splits, he is only allowed to play hit and stand. The bets are made before the choices of the player, so it is considered the same for both hands in the case of a split. If one hand looses, then the player continues with the other hand. If both hands win, then the player wins double the bet. Number-cards count as their natural value; the jack, queen, and king (also known as "face cards" or "pictures") count as 10; aces are valued as either 1 or 11 (i.e., the program should sum up with both values (1 and 11) for Ace and take the value that makes the sum less or equal than 21, but closer to 21.) If the hand value exceeds 21 points, it busts, and all bets on it are immediately forfeit. Details about player decisions are available here Check that the same cards are not distributed as duplicates in the same game round! After the user finished playing, the dealer's hand is resolved by drawing cards until the hand busts or achieves a value of 17 or higher. The dealer never doubles, splits nor surrenders. If the dealer busts, then the user wins. If the dealer does not bust, the user wins the bet if his hand is higher than the computer's, and loses if it is lower. In the case of a tied score, known as "push" or "standoff", bets are normally returned without adjustment. Wins are paid out at 1:1, or equal to the wager, except for winning blackjacks, which are traditionally paid at 3:2 (meaning the player receives three dollars for every two bet), or one and a half times the wager. Aces are valued 11 by the computer. The Blackjack gui code is: import java.awt.Color; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Scanner; import java.io.IOException; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.border.Border; import javax.swing.border.LineBorder; import java.util.Scanner; public class Blackjack_GUI extends JFrame { int rounds = 0; int purse = 20; JPanel p0 = new JPanel(); JPanel p01 = new JPanel(); JPanel p02 = new JPanel(); JPanel p1 = new JPanel(); JPanel p12 = new JPanel(); JPanel p2 = new JPanel(); JPanel p21 = new JPanel(); JPanel p211 = new JPanel(); JPanel p22 = new JPanel(); JPanel p222 = new JPanel(); JPanel p3 = new JPanel(); JPanel p32 = new JPanel(); JPanel p4 = new JPanel(); JPanel p5 = new JPanel(); JPanel p6 = new JPanel(); JLabel l1 = new JLabel(); JLabel l21 = new JLabel(); JLabel l22 = new JLabel(); JLabel[] icons1 = new JLabel[10]; JLabel[] icons2 = new JLabel[10]; int bet = 0; JLabel l41 = new JLabel(); JButton b41 = new JButton("$1"); JButton b42 = new JButton("$2"); JLabel l42 = new JLabel(); JLabel l5 = new JLabel(); JButton b51 = new JButton("Stay"); JButton b52 = new JButton("Hit"); JLabel l6 = new JLabel(); JButton b6 = new JButton("Next"); // cards int[][] previous_cards = new int[50][2]; int nop = 0; int[][] hand1 = new int[10][2]; // human hand int no1 = 0; int[][] hand2 = new int[10][2]; // computer int no2 = 0; int sum1 = 0; int sum2 = 0; // Constructor Blackjack_GUI(){ this.setSize(1000, 800); this.setLayout(new GridLayout(2,1)); this.add(p2); this.add(p3); p3.setLayout(new GridLayout(5,1)); p3.add(p0); p3.add(p1); p3.add(p4); p3.add(p5); p3.add(p6); //j11.setIcon(card_to_ImageIcon(sorted1[0])); rounds = 1; p0.setLayout(new GridLayout(1,2)); p0.add(p01); p0.add(p02); p01.add(l21); p02.add(l22); p01.setBorder(new LineBorder(new Color(0,0,0),2)); p02.setBorder(new LineBorder(new Color(0,0,0),2)); p1.add(l1); p2.setLayout(new GridLayout(1,2)); p2.add(p211); p2.add(p222); p211.setBorder(new LineBorder(new Color(0,0,0),2)); p222.setBorder(new LineBorder(new Color(0,0,0),2)); p211.setLayout(new GridLayout(1,5)); p222.setLayout(new GridLayout(1,5)); p4.add(l41); p4.add(b41); p4.add(b42); p4.add(l42); l41.setText("Bet: "); p5.add(l5); l5.setText("Action: "); p5.add(b51); p5.add(b52); p6.add(l6); p6.add(b6); b41.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) { refreshDisplay("b41"); } } ); b42.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) { refreshDisplay("b42"); } } ); b51.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) { refreshDisplay("b51"); } } ); b52.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) { refreshDisplay("b52"); } } ); b6.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) { refreshDisplay("b6"); } } ); // ACTIONS l1.setText("Round "+rounds+" "+"Action: select bet"); // generate one card hand1[no1] = generate_card(previous_cards,nop); previous_cards[nop][0] = hand1[no1][0]; previous_cards[nop][1] = hand1[no1][1]; nop++; no1++; // generate one card hand1[no1] = generate_card(previous_cards,nop); previous_cards[nop][0] = hand1[no1][0]; previous_cards[nop][1] = hand1[no1][1]; nop++; no1++; // generate computer hard hand2[no2] = generate_card(previous_cards,nop); previous_cards[nop][0] = hand2[no2][0]; previous_cards[nop][1] = hand2[no2][1]; nop++; no2++; for(int i=0; i New purse: $ "); b51.disable(); b52.disable(); b6.disable(); setVisible(true); repaint(); } public static void main(String[] args) throws IOException { Blackjack_GUI pg = new Blackjack_GUI(); } public void refreshDisplay(String option){ System.out.println("Option: "+option); if( option.equals("b41") || option.equals("b42") ){ l1.setText("Round "+rounds+" "+"Action: select stand, hit"); if( option.equals("b41") ){ bet = 1; }else bet = 2; l42.setText("Bet: $"+bet); b41.disable(); b42.disable(); b51.enable(); b52.enable(); b6.disable(); } else if(option.equals("b52")){ // generate one card hand1[no1] = generate_card(previous_cards,nop); previous_cards[nop][0] = hand1[no1][0]; previous_cards[nop][1] = hand1[no1][1]; nop++; no1++; p211.removeAll(); for(int i=0; i New purse: $ "); } else if(option.equals("b51")){ } else if(option.equals("b6")){ } else System.out.println("Invalid option: "+option); repaint(); } public static ImageIcon card_to_ImageIcon(int[] c){ String fileString = "images/Playing_card_"; if(c[1]==1) fileString += "heart"; else if(c[1]==2) fileString += "diamond"; else if(c[1]==2) fileString += "club"; else fileString += "spade"; fileString += "_"; if(2<=c[0] && c[0]<=10) fileString += c[0]; else if(c[0]==11) fileString += "J"; else if(c[0]==12) fileString += "Q"; else if(c[0]==13) fileString += "K"; else fileString += "A"; fileString += ".jpg"; return new ImageIcon(fileString); } public static int sum_hand(int[][] hand1,int no1){ int sum = 0; for(int i=0; i<=10) sum += hand1[i][0]; else sum += 10; } return sum; } public static int[] generate_card(int[][] previous_cards,int nop){ boolean duplicate = false; int[] card = new int[2]; do{ duplicate = false; card[0] = (int) (Math.random()*13 + 2); card[1] = (int) (Math.random()*4 + 1); // compare all the previous hands with the current hand for(int i=0; i<=c[0] && c[0]<=10) card += c[0]; else if(c[0]==11) card += "Jack"; else if(c[0]==12) card += "Queen"; else if(c[0]==13) card += "king"; else if(c[0]==14) card += "Ace"; else card += "card_to_String error: card number="+c[0]; card += " of "; if(c[1]==1) card += "hearts"; else if(c[1]==2) card += "diamonds"; else if(c[1]==2) card += "clubs"; else card += "spades"; return card; } }

Explanation / Answer

i am not getting your code as it is unreadable, so i am posting my code try it :) import java.util.*; import java.io.*; import java.lang.*; public class BlackJackClassProject { public static void main(String[] args) throws IOException { BufferedReader dataIn = new BufferedReader (new InputStreamReader(System.in)); //Declare Variables int again = 0; do { double range = 26; int randomGenNum; int kitty = 1000; int yourBet; int userHandValue = 0; int userDrawnValue; int dealerHandValue = 0; int dealerDrawnValue; String playAgain; String hit = ""; String strBetAmount; String userCard, dealerCard; int[] arrayCardValues = {0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10}; String[] arrayCardSuites = { "","","Ace/Clubs","Ace/Diamonds","Ace/Hearts","Ace/Spades", "2/Clubs","2/Diamonds","2/Hearts","2/Spades","3/Clubs","3/Diamonds","3/Hearts","3/Spades", "4/Clubs","4/Diamonds","4/Hearts","4/Spades","5/Clubs","5/Diamonds","5/Hearts","5/Spades", "6/Clubs","6/Diamonds","6/Hearts","6/Spades","7/Clubs","7/Diamonds","7/Hearts","7/Spades", "8/Clubs","8/Diamonds","8/Hearts","8/Spades","9/Clubs","9/Diamonds","9/Hearts","9/Spades", "10/Clubs","10/Diamonds","10/Hearts","10/Spades","Jack/Clubs","Jack/Diamonds","Jack/Hearts","Jack/Spades" ,"Queen/Clubs","Queen/Diamonds","Queen/Hearts","Queen/Spades","King/Clubs","King/Diamonds","King/Hearts","King/Spades" }; //ask the user how much they want to bet System.out.println("How much do you want to bet?"); strBetAmount = dataIn.readLine(); yourBet = Integer.parseInt(strBetAmount); //draw three cards (one card face up for dealer, two for player) //dealer first drawn card randomGenNum = (int)((range * Math.random()) + 1)*2; //assigning the dealer hand value & card, pulling index from array dealerHandValue = arrayCardValues[randomGenNum]; //Check if the dealer got an ace if ((randomGenNum >= 2) && (randomGenNum = 2) && (randomGenNum = 2) && (randomGenNum = 2) && (randomGenNum