1. Are you ready for the Galaxy S20? Here is everything we know so far!

help!?!

Discussion in 'Android Development' started by TimeForPeace, Apr 28, 2012.

  1. TimeForPeace

    TimeForPeace Lurker
    Thread Starter

    for my school assingment i have to make an android application for a card game-black jack.yes,i have found different and so many source codes on the web but when i copy them in my eclipse there always seems to be an error.
    since i don't have time to learn the basis for java NOW(but i will,because i'm very interested in it) i am really hoping that someone can explain me how to make it work.

    here is one source code:



    Code (Text):
    1. package com.bj.android.bj;
    2.  
    3.  import java.io.*;
    4.  
    5.  public class BlackjackActivity
    6.  {
    7.  public static void main(String[] args) throws IOException
    8.  {
    9.  
    10.  BufferedReader dataIn = new BufferedReader (new InputStreamReader(System.in));
    11.  
    12.  //Declare Variables
    13.  int again = 0;
    14.  do
    15.  {
    16.  double range = 26;
    17.  int randomGenNum;
    18.  int kitty = 1000;
    19.  int yourBet;
    20.  int userHandValue = 0;
    21.  int userDrawnValue;
    22.  int dealerHandValue = 0;
    23.  int dealerDrawnValue;
    24.  String playAgain;
    25.  String hit = "";
    26.  String strBetAmount;
    27.  String userCard, dealerCard;
    28.  
    29.  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};
    30.  String[] arrayCardSuites =
    31.  {
    32.  "","","Ace/Clubs","Ace/Diamonds","Ace/Hearts","Ace/Spades",
    33.  "2/Clubs","2/Diamonds","2/Hearts","2/Spades","3/Clubs","3/Diamonds","3/Hearts","3/Spades",
    34.  "4/Clubs","4/Diamonds","4/Hearts","4/Spades","5/Clubs","5/Diamonds","5/Hearts","5/Spades",
    35.  "6/Clubs","6/Diamonds","6/Hearts","6/Spades","7/Clubs","7/Diamonds","7/Hearts","7/Spades",
    36.  "8/Clubs","8/Diamonds","8/Hearts","8/Spades","9/Clubs","9/Diamonds","9/Hearts","9/Spades",
    37.  "10/Clubs","10/Diamonds","10/Hearts","10/Spades","Jack/Clubs","Jack/Diamonds","Jack/Hearts","Jack/Spades"
    38.  ,"Queen/Clubs","Queen/Diamonds","Queen/Hearts","Queen/Spades","King/Clubs","King/Diamonds","King/Hearts","King/Spades"
    39.  };
    40.  
    41.  //ask the user how much they want to bet
    42.  System.out.println("How much do you want to bet?");
    43.  strBetAmount = dataIn.readLine();
    44.  yourBet = Integer.parseInt(strBetAmount);
    45.  //draw three cards (one card face up for dealer, two for player)
    46.  
    47.  //dealer first drawn card
    48.  randomGenNum = (int)((range * Math.random()) + 1)*2;
    49.  //assigning the dealer hand value & card, pulling index from array
    50.  dealerHandValue = arrayCardValues[randomGenNum];
    51.  //Check if the dealer got an ace
    52.  if ((randomGenNum >= 2) && (randomGenNum <= 5))
    53.  {
    54.  dealerHandValue = dealerHandValue + 10;
    55.  }
    56.  int tempDealerHandValue = dealerHandValue;
    57.  dealerCard = arrayCardSuites[randomGenNum];
    58.  //displaying values to the screen
    59.  System.out.println("The dealer is showing a " + dealerCard);
    60.  //System.out.println("The value is " + dealerHandValue);
    61.  //dealers second drawn card
    62.  randomGenNum = (int)((range * Math.random()) + 1)*2;
    63.  //assigning the dealer hand value & card, pulling index from array
    64.  dealerHandValue = arrayCardValues[randomGenNum];
    65.  //Check if the dealer got an ace
    66.  if ((dealerHandValue != 11) && (randomGenNum >= 2) && (randomGenNum <= 5))
    67.  {
    68.  dealerHandValue = dealerHandValue + 10;
    69.  }
    70.  dealerCard = arrayCardSuites[randomGenNum];
    71.  //displaying values to the screen
    72.  //System.out.println("The dealers second card is " + dealerCard);
    73.  //System.out.println("The dealers total hand value is: " + (tempDealerHandValue + dealerHandValue));
    74.  
    75.  
    76.  
    77.  //users first drawn card
    78.  randomGenNum = (int)((range * Math.random()) + 1)*2;
    79.  //assigning the user hand value & card, pulling index from array
    80.  userHandValue = arrayCardValues[randomGenNum];
    81.  //Check if the user got an ace
    82.  if ((randomGenNum >= 2) && (randomGenNum <= 5))
    83.  {
    84.  userHandValue = userHandValue + 10;
    85.  }
    86.  int tempUserHandValue = userHandValue;
    87.  userCard = arrayCardSuites[randomGenNum];
    88.  //displaying values to the screen
    89.  System.out.println("Your first card is " + userCard);
    90.  
    91.  
    92.  //users second drawn card
    93.  randomGenNum = (int)((range * Math.random()) + 1)*2;
    94.  //assigning the user hand value & card, pulling index from array
    95.  userHandValue = arrayCardValues[randomGenNum];
    96.  //Check if the user got an ace
    97.  if ((userHandValue != 11) && (randomGenNum >= 2) && (randomGenNum <= 5))
    98.  {
    99.  userHandValue = userHandValue + 10;
    100.  }
    101.  userCard = arrayCardSuites[randomGenNum];
    102.  //displaying values to the screen
    103.  System.out.println("Your second card is " + userCard);
    104.  System.out.println("Your total hand value is: " + (tempUserHandValue + userHandValue));
    105.  
    106.  }
    107.  while (again == 1);
    108.  
    109.  }
    110.  
    PLEASE.I'M DESPERATE.
     


Loading...

Share This Page

Loading...