help with my blackjack program

i have two questions

1: My program just keeps on using the same card value throughtout the whole program. Each of my cards are determined by a random number. The problem is my random number keeps on staying the same for every game which is held together by a loop that keeps on interating until the user runs of of money or wants to quit. Here is my random number method-

public int getRanNum(){
RanNum = (int)((13 - 2 + 2) * Math.random() + 2);
return(RanNum);
}

2. My 2nd problem is my betting. When the user inputs a bet greater than the current amount of money, it goes to the checkBet method which has the user input a new bet. However it just uses the first input of bet in my program. Here is the code-

[b]from main method...[/b]

System.out.println("How much of your " + money.format(Cash) + " do you want to bet ");
bet = input.nextInt();
play.checkBet(bet, Cash);


[b]from my class called card....[/b]

public void checkBet(int bet, int Cash){
if(bet > Cash){
Scanner input = new Scanner(System.in);
System.out.println("Not enough money enter a lower amount ");
bet = input.nextInt();
}
}

Comments

  • : i have two questions
    :
    : 1: My program just keeps on using the same card value throughtout
    : the whole program. Each of my cards are determined by a random
    : number. The problem is my random number keeps on staying the same
    : for every game which is held together by a loop that keeps on
    : interating until the user runs of of money or wants to quit. Here is
    : my random number method-
    :
    : public int getRanNum(){
    : RanNum = (int)((13 - 2 + 2) * Math.random() + 2);
    : return(RanNum);
    : }
    :
    : 2. My 2nd problem is my betting. When the user inputs a bet greater
    : than the current amount of money, it goes to the checkBet method
    : which has the user input a new bet. However it just uses the first
    : input of bet in my program. Here is the code-
    :
    : [b]from main method...[/b]
    :
    : System.out.println("How much of your " + money.format(Cash) + " do
    : you want to bet ");
    : bet = input.nextInt();
    : play.checkBet(bet, Cash);
    :
    :
    : [b]from my class called card....[/b]
    :
    : public void checkBet(int bet, int Cash){
    : if(bet > Cash){
    : Scanner input = new Scanner(System.in);
    : System.out.println("Not enough money enter a lower
    : amount ");
    : bet = input.nextInt();
    : }
    : }
    :
    1) I've tested your random generator with this line several times:
    [code]
    for (int i = 0; i < 10; i++)
    System.out.print((int)((13 - 2 + 2) * Math.random() + 2)+", ");
    [/code]
    and never got the same value for all 10. Here's the result of one of those runs: 5, 14, 4, 7, 8, 9, 13, 6, 3, 7,

    2) In Java all method parameters are non-variable. Thus if the value of a parameter is changed within a method, it is never reflected back to the calling method. The solution is to make your method a function, which returns the bet value.

    Note: I've removed the second thread you created since it was the same as this one.
  • : : i have two questions
    : :
    : : 1: My program just keeps on using the same card value throughtout
    : : the whole program. Each of my cards are determined by a random
    : : number. The problem is my random number keeps on staying the same
    : : for every game which is held together by a loop that keeps on
    : : interating until the user runs of of money or wants to quit. Here is
    : : my random number method-
    : :
    : : public int getRanNum(){
    : : RanNum = (int)((13 - 2 + 2) * Math.random() + 2);
    : : return(RanNum);
    : : }
    : :
    : : 2. My 2nd problem is my betting. When the user inputs a bet greater
    : : than the current amount of money, it goes to the checkBet method
    : : which has the user input a new bet. However it just uses the first
    : : input of bet in my program. Here is the code-
    : :
    : : [b]from main method...[/b]
    : :
    : : System.out.println("How much of your " + money.format(Cash) + " do
    : : you want to bet ");
    : : bet = input.nextInt();
    : : play.checkBet(bet, Cash);
    : :
    : :
    : : [b]from my class called card....[/b]
    : :
    : : public void checkBet(int bet, int Cash){
    : : if(bet > Cash){
    : : Scanner input = new Scanner(System.in);
    : : System.out.println("Not enough money enter a lower
    : : amount ");
    : : bet = input.nextInt();
    : : }
    : : }
    : :
    : 1) I've tested your random generator with this line several times:
    : [code]:
    : for (int i = 0; i < 10; i++)
    : System.out.print((int)((13 - 2 + 2) * Math.random() + 2)+", ");
    : [/code]:
    : and never got the same value for all 10. Here's the result of one of
    : those runs: 5, 14, 4, 7, 8, 9, 13, 6, 3, 7,
    :
    : 2) In Java all method parameters are non-variable. Thus if the value
    : of a parameter is changed within a method, it is never reflected
    : back to the calling method. The solution is to make your method a
    : function, which returns the bet value.
    :
    : Note: I've removed the second thread you created since it was the
    : same as this one.

    Thank you very much. Ps. if anyone can find any individual .gif or .jpeg pictures of all the individual cards please contect me
  • : : : i have two questions
    : : :
    : : : 1: My program just keeps on using the same card value throughtout
    : : : the whole program. Each of my cards are determined by a random
    : : : number. The problem is my random number keeps on staying the same
    : : : for every game which is held together by a loop that keeps on
    : : : interating until the user runs of of money or wants to quit. Here is
    : : : my random number method-
    : : :
    : : : public int getRanNum(){
    : : : RanNum = (int)((13 - 2 + 2) * Math.random() + 2);
    : : : return(RanNum);
    : : : }
    : : :
    : : : 2. My 2nd problem is my betting. When the user inputs a bet greater
    : : : than the current amount of money, it goes to the checkBet method
    : : : which has the user input a new bet. However it just uses the first
    : : : input of bet in my program. Here is the code-
    : : :
    : : : [b]from main method...[/b]
    : : :
    : : : System.out.println("How much of your " + money.format(Cash) + " do
    : : : you want to bet ");
    : : : bet = input.nextInt();
    : : : play.checkBet(bet, Cash);
    : : :
    : : :
    : : : [b]from my class called card....[/b]
    : : :
    : : : public void checkBet(int bet, int Cash){
    : : : if(bet > Cash){
    : : : Scanner input = new Scanner(System.in);
    : : : System.out.println("Not enough money enter a lower
    : : : amount ");
    : : : bet = input.nextInt();
    : : : }
    : : : }
    : : :
    : : 1) I've tested your random generator with this line several times:
    : : [code]: :
    : : for (int i = 0; i < 10; i++)
    : : System.out.print((int)((13 - 2 + 2) * Math.random() + 2)+", ");
    : : [/code]: :
    : : and never got the same value for all 10. Here's the result of one of
    : : those runs: 5, 14, 4, 7, 8, 9, 13, 6, 3, 7,
    : :
    : : 2) In Java all method parameters are non-variable. Thus if the value
    : : of a parameter is changed within a method, it is never reflected
    : : back to the calling method. The solution is to make your method a
    : : function, which returns the bet value.
    : :
    : : Note: I've removed the second thread you created since it was the
    : : same as this one.
    :
    : Thank you very much. Ps. if anyone can find any individual .gif or
    : .jpeg pictures of all the individual cards please contect me
    :
    Why don't you make them yourself? It isn't as hard as it sounds. Nearly every font has the card-suit symbols included: ???? (I hope these 4 will appear correctly). You can easily type them into paint (or another drwing program) and add a number/letter to it to produce an image.
    Alternatively you could dynamically let your program draw them onto a Graphics object to produce the images.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion