d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Blackjack / Card Program > Need Help With 1 Part Pls
Prev123Next
Add Reply New Topic New Poll
Member
Posts: 4,625
Joined: Jul 3 2009
Gold: 6,520.00
Feb 1 2013 10:04pm
Quote (Schwag @ Feb 1 2013 04:12pm)
Unless the Dealer and BlackJack classes are in the same directory/package, you must import the Dealer class after the package declaration in the BlackJack class.


thx, it runs now, but im getting errors for the part of code that adds a card to the player's hand. :(

in Dealer class:

if(i < 2){
dealPlayer(newCard);
}
else{
dealDealer(newCard);
---------------
public void addDealerCard(Card card){
dealerHand[countDealer] = card;
countDealer++;
System.out.println("Dealers card: " + dealerHand[countDealer].getCard());
}
public void dealDealer(Card card){
dealer.addDealerCard(card);
}
public void dealPlayer(Card card){
player.addPlayerCard(card);
}
--------------------------
in Player class:
Card[] playerHand = new Card[2];
int count = 0;

//method to add a card to the player's hand
public void addPlayerCard(Card card){
playerHand[count] = card;
count++;
-----------------------------

help is very appreciated, i donate fg :)

This post was edited by shinigamiapple777 on Feb 1 2013 10:07pm
Member
Posts: 4,980
Joined: Jan 16 2010
Gold: 0.00
Warn: 20%
Feb 2 2013 01:22am
Quote (shinigamiapple777 @ 2 Feb 2013 06:04)
thx, it runs now, but im getting errors for the part of code that adds a card to the player's hand. :(

in Dealer class:

if(i < 2){
                dealPlayer(newCard);
            }
            else{
              dealDealer(newCard);
---------------
public void addDealerCard(Card card){
        dealerHand[countDealer] = card;
        countDealer++;
        System.out.println("Dealers card: " + dealerHand[countDealer].getCard());
    }
      public void dealDealer(Card card){
        dealer.addDealerCard(card);
    }
        public void dealPlayer(Card card){
        player.addPlayerCard(card);
    }
--------------------------
in Player class:
Card[] playerHand = new Card[2];
    int count = 0;
   
    //method to add a card to the player's hand
    public void addPlayerCard(Card card){
        playerHand[count] = card;
        count++;
-----------------------------

help is very appreciated, i donate fg :)


You should posts the errors you are getting, as well as your entire code in code tags, as the source for errors can lie in every line of your code.
Member
Posts: 4,625
Joined: Jul 3 2009
Gold: 6,520.00
Feb 10 2013 10:02am
is there something wrong in this code that would make it so that it is always true that i = 0? i'm trying to make it so that after i deal one card, it would add 1 to i for all variables i in two methods for the class.
edit: nvm pretty sure that it should work, but my problem lies with me not using my shuffleDeck method which assigns values to the deck other than private int[] deck = new int [51];.

This post was edited by shinigamiapple777 on Feb 10 2013 10:18am
Member
Posts: 4,625
Joined: Jul 3 2009
Gold: 6,520.00
Feb 11 2013 10:19am
Quote (Grandebedte @ Feb 2 2013 03:22am)
You should posts the errors you are getting, as well as your entire code in code tags, as the source for errors can lie in every line of your code.


ur inbox full again ;(

not sure where you were referring to for your last message
You're declaring a Dealer dealer as a field, but this is null and is unused. What you probably meant was 'this.dealerHandValue'.

so help to fix it would be very much appreciated. have till wed. to fix error ;o
Member
Posts: 4,625
Joined: Jul 3 2009
Gold: 6,520.00
Feb 11 2013 11:05am
Quote (shinigamiapple777 @ Feb 11 2013 12:19pm)
ur inbox full again ;(

not sure where you were referring to for your last message
You're declaring a Dealer dealer as a field, but this is null and is unused. What you probably meant was 'this.dealerHandValue'.

so help to fix it would be very much appreciated. have till wed. to fix error ;o


nvm, got it fixed :). just had to remove Dealer dealer; , and change dealer.dealerHandValue; to dealerHandValue;

now i just have to figure out...change it back to use shuffle. and how to auto set x = 0 so that the player can't hit any more cards once past 21, instead of saying 'you've busted, please enter 0'.

This post was edited by shinigamiapple777 on Feb 11 2013 11:34am
Member
Posts: 4,625
Joined: Jul 3 2009
Gold: 6,520.00
Feb 11 2013 12:03pm
Quote (shinigamiapple777 @ Feb 11 2013 01:05pm)
nvm, got it fixed :). just had to remove Dealer dealer; , and change dealer.dealerHandValue; to dealerHandValue;

now i just have to figure out...change it back to use shuffle. and how to auto set x = 0 so that the player can't hit any more cards once past 21, instead of saying 'you've busted, please enter 0'.


:)
got it so that shuffle is working, have to try and fix making the scanner auto set to 0 if the player busts ( hand value > 21), or if there are more than 5 cards in hand..
Member
Posts: 4,625
Joined: Jul 3 2009
Gold: 6,520.00
Feb 11 2013 12:18pm
Quote (shinigamiapple777 @ Feb 11 2013 02:03pm)
:)
got it so that shuffle is working, have to try and fix making the scanner auto set to 0 if the player busts ( hand value > 21), or if there are more than 5 cards in hand..


and i think i got that finished :)

it is all starting to make sense...i like this now.
Member
Posts: 4,625
Joined: Jul 3 2009
Gold: 6,520.00
Feb 15 2013 11:06am
I could use some help with this next week's project about adding my blackjack code into a new project, so if anyone can help - pls pm.
Member
Posts: 4,625
Joined: Jul 3 2009
Gold: 6,520.00
Feb 15 2013 03:37pm
Quote (shinigamiapple777 @ Feb 15 2013 01:06pm)
I could use some help with this next week's project about adding my blackjack code into a new project, so if anyone can help - pls pm.


I have used netbeans to code a game of blackjack which works fine, now I need to add it to a project called GameConsole - which will house multiple games. i have to make an abstract class Game. then i have to 'use/think interfaces' to allow GameConsole to call a method to take an object that is 'playable'.

overall : when GameConsole is run, a console menu will pop up showing what games are available to play. for now, it's just blackjack, so that's the only option that will be available. then by choosing blackjack, it will run blackjack.

PM please if you can help, will donate :)
Member
Posts: 4,625
Joined: Jul 3 2009
Gold: 6,520.00
Feb 19 2013 07:32pm
Quote (shinigamiapple777 @ Feb 15 2013 05:37pm)
I have used netbeans to code a game of blackjack which works fine, now I need to add it to a project called GameConsole - which will house multiple games. i have to make an abstract class Game. then i have to 'use/think interfaces' to allow GameConsole to call a method to take an object that is 'playable'.

overall : when GameConsole is run, a console menu will pop up showing what games are available to play. for now, it's just blackjack, so that's the only option that will be available. then by choosing blackjack, it will run blackjack.

PM please if you can help, will donate :)


could still use help with this. atm im trying to figure out 1. why i'm getting errors:

Code
res = Reflection.filterMethods(this, getDeclaredMethods0(publicOnly));
if ((res = searchMethods(privateGetDeclaredMethods(true),
 Method method = getMethod0(name, parameterTypes);


and 2. about abstract classes : I have an abstract class Game, and a class called BlackJack. BlackJack extends Game. in my GameConsole class, I have Game blackjack = new BlackJack(); how do i call methods from the BlackJack class?

or if i try:
Code
BlackJack test = new BlackJack();
               test.playGame();


i get error:
Exception in thread "main" java.lang.NoSuchMethodError: BlackJack.playGame()V


This post was edited by shinigamiapple777 on Feb 19 2013 07:49pm
Go Back To Programming & Development Topic List
Prev123Next
Add Reply New Topic New Poll