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

help.please!

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.
     


  2. TimeForPeace

    TimeForPeace Lurker
    Thread Starter

    here is one source code:

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

    lunatic59 Moderati ergo sum
    Moderator

    You should really be asking that in the Android Development section. If it's a school assignment, shouldn't you seek help from your instructor?
     
    argedion, SUroot and Seanette like this.
  4. SUroot

    SUroot Extreme Android User

    Can I also recommend the use of code tags for forum posts containing source code? Makes it all a bit more readable.
     
    argedion likes this.
  5. argedion

    argedion The TechnoFrog

    Not only would this be more appropriate in the Developers section It will also be helpful to them if you can give them the errors your getting. What are you using to compile with? Whats your system? Where are the Sources coming from. I'm sure these are just a few things the Dev's will need to know in order to help you. Good Luck to you.
     
  6. Unforgiven

    Unforgiven ...eschew obfuscation...
    Moderator

    I've moved this to the application development forum so you can get some better eyes on it.:)
     
Loading...

Share This Page

Loading...