Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package practice;
- import java.util.Scanner;
- import java.util.Random;
- public class deck {
- Scanner scan = new Scanner(System.in);
- Random rand = new Random();
- String[] cards = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
- String[] suits = {" of Hearts", " of Diamonds", " of Spades", " of Clubs"};
- String[][] deck = new String[suits.length][cards.length];
- public deck(){
- int shuffleCards, shuffleSuits, playerPoints, dealerPoints, playerTotal, dealerTotal, wins, loses, pushes;
- showCard = "";
- playAgain = "y";
- score = "";
- playerTotal = 0;
- playerPoints = 0;
- dealerPoints = 0;
- dealerTotal = 0;
- wins = loses = pushes = 0;
- System.out.print("Your cards: ");
- for(int a=1; a<=3; a++)
- {
- shuffleCards = rand.nextInt(cards.length-1) + 0;
- shuffleSuits = rand.nextInt(suits.length-1) + 0;
- shuffleCards = 0;
- shuffleSuits = 0;
- selectedCard.append(cards[shuffleCards].concat(suits[shuffleSuits]));
- currentCard = cards[shuffleCards].concat(suits[shuffleSuits]);
- System.out.println("current card" + currentCard);
- checkCards.add(currentCard);
- System.out.println("currentCard " + checkCards);
- for(int x=0; x<checkCards.length; x++)
- {
- public getCard = (String) checkCards.get(x);
- if(currentCard.matches(selectedCard.toString()))
- {
- shuffleCards = rand.nextInt(cards.length-1) + 0;
- shuffleSuits = rand.nextInt(suits.length-1) + 0;
- System.out.println("That card was already selected");
- }
- System.out.println("getCard["+x+"] = " + (String) checkCards.get(x));
- }
- System.out.println(cards[shuffleCards] + suits[shuffleSuits] );
- if(shuffleCards == 1)
- {
- playerPoints = 2;
- }
- if(shuffleCards == 2)
- {
- playerPoints = 3;
- }
- if(shuffleCards == 3)
- {
- playerPoints = 4;
- }
- if(shuffleCards == 4)
- {
- playerPoints = 5;
- }
- if(shuffleCards == 5)
- {
- playerPoints = 6;
- }
- if(shuffleCards == 6)
- {
- playerPoints = 7;
- }
- if(shuffleCards == 7)
- {
- playerPoints = 8;
- }
- if(shuffleCards == 8)
- {
- playerPoints = 9;
- }
- if(shuffleCards == 9 || shuffleCards == 10 || shuffleCards == 11 || shuffleCards == 12)
- {
- playerPoints = 10;
- }
- if((shuffleCards == 10 && shuffleSuits == 2 )|| (shuffleCards == 10 && shuffleSuits == 0) || (shuffleCards == 12 && shuffleSuits == 1))
- {
- playerPoints = 13;
- }
- if(shuffleCards == 2 && shuffleSuits == 3)
- {
- playerPoints = 0;
- }
- if(shuffleCards == 0 && (playerTotal <= 22))
- {
- playerPoints = 11;
- }
- if(shuffleCards == 0 && (playerTotal > 22))
- {
- playerPoints = 1;
- }
- playerTotal = playerPoints + playerTotal;
- showCard = showCard.concat(cards[shuffleCards]).concat(suits[shuffleSuits].concat(", "));
- }
- System.out.println("(Total " + playerTotal );
- System.out.println();
- System.out.println("Would you like another card (Y/N)? ");
- anotherCard = scan.nextLine();
- while(anotherCard.equalsIgnoreCase("y"))
- {
- System.out.println("Your cards: " + showCard);
- shuffleCards = rand.nextInt(cards.length-1) + 0;
- shuffleSuits = rand.nextInt(suits.length-1) + 0;
- if(shuffleCards == 1)
- {
- playerPoints = 2;
- }
- if(shuffleCards == 2)
- {
- playerPoints = 3;
- }
- if(shuffleCards == 3)
- {
- playerPoints = 4;
- }
- if(shuffleCards == 4)
- {
- playerPoints = 5;
- }
- if(shuffleCards == 5)
- {
- playerPoints = 6;
- }
- if(shuffleCards == 6)
- {
- playerPoints = 7;
- }
- if(shuffleCards == 7)
- {
- playerPoints = 8;
- }
- if(shuffleCards == 8)
- {
- playerPoints = 9;
- }
- if(shuffleCards == 9 || shuffleCards == 10 || shuffleCards == 11 || shuffleCards == 12)
- {
- playerPoints = 10;
- }
- if(shuffleCards == 10 && shuffleSuits == 2 || shuffleCards == 10 && shuffleSuits == 0 || shuffleCards == 12 && shuffleSuits == 1)
- {
- playerPoints = 13;
- }
- if(shuffleCards ==11 && shuffleSuites ==1||3)
- playerPoints = 13;
- if(shuffleCards ==13 && shuffleSuites ==2)
- playerPoints = 13;
- if(shuffleCards == 3 && shuffleSuits == 4)
- {
- playerPoints = 0;
- }
- if(shuffleCards == 0 && (playerTotal <= 22))
- {
- playerPoints = 11;
- }
- if(shuffleCards == 0 && (playerTotal > 22))
- {
- playerPoints = 1;
- }
- playerTotal = playerPoints + playerTotal;
- System.out.println("(Total " + playerTotal );
- System.out.println();
- System.out.println("Would you like another card (Y/N)? ");
- anotherCard = scan.nextLine();
- }
- System.out.println();
- System.out.println("The dealer drew: ");
- while(dealerTotal <= 26)
- {
- shuffleCards = rand.nextInt(cards.length-1) + 0;
- shuffleSuits = rand.nextInt(suits.length-1) + 0;
- if(shuffleCards == 1)
- {
- dealerPoints = 2;
- }
- if(shuffleCards == 2)
- {
- dealerPoints = 3;
- }
- if(shuffleCards == 3)
- {
- dealerPoints = 4;
- }
- if(shuffleCards == 4)
- {
- dealerPoints = 5;
- }
- if(shuffleCards == 5)
- {
- dealerPoints = 6;
- }
- if(shuffleCards == 6)
- {
- dealerPoints = 7;
- }
- if(shuffleCards == 7)
- {
- dealerPoints = 8;
- }
- if(shuffleCards == 8)
- {
- dealerPoints = 9;
- }
- if(shuffleCards == 9 || shuffleCards == 10 || shuffleCards == 11 || shuffleCards == 12)
- {
- dealerPoints = 10;
- }
- if((shuffleCards == 10 && shuffleSuits == 2 )|| (shuffleCards == 10 && shuffleSuits == 0) || (shuffleCards == 12 && shuffleSuits == 1))
- {
- dealerPoints = 13;
- }
- if(shuffleCards == 2 && shuffleSuits == 3)
- {
- dealerPoints = 0;
- }
- if(shuffleCards == 0 && (dealerTotal <= 22))
- {
- dealerPoints = 11;
- }
- if(shuffleCards == 0 && (dealerTotal > 22))
- {
- dealerPoints = 1;
- }
- dealerTotal = dealerPoints + dealerTotal;
- System.out.println(cards[shuffleCards] + suits[shuffleSuits].concat(", "));
- }
- System.out.println("(Total " + dealerTotal );
- System.out.println();
- if((33 - playerTotal < 33 - dealerTotal) && playerTotal <= 33 || dealerTotal > 33)
- {
- System.out.println("You win!");
- wins++;
- }
- if((33 - playerTotal > 33 - dealerTotal) && dealerTotal <= 33 || playerTotal > 33)
- {
- System.out.println("Sorry, you lose");
- loses++;
- }
- if(playerTotal == dealerTotal)
- {
- score = "tied!";
- pushes++;
- }
- System.out.println("You " + score + " Current Total :Wins - " + wins + " Ties : " + pushes + " Loses : " + loses);
- System.out.println();
- else System.out.println("Would you like to play again (Y/Q)? ");
- playAgain = scan.nextLine();
- if(playAgain.equalsIgnoreCase("y"))
- {
- playerTotal = 0;
- dealerTotal = 0;
- playerPoints = 0;
- dealerPoints = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement