Results 1 to 4 of 4
  1. #1
    treeface99 is offline Member
    Join Date
    Jan 2012
    Posts
    12
    Rep Power
    0

    Default Creating an object containing an array and int - small error

    Hi,

    I am writing a black jack program and have created an object containing an array if ints (the players hand) and one other int value (the dealers faced up card). But when i try to create an instance of the object, i seem to be declaring it wrong. Here is my code. on the last line 'hand []' is underlined showing 'The type of the expression must be an array type but it resolved to CreateHand'

    public class CreateHand {

    int cardA = 0;
    int cardB = 0;
    int dealersCard;
    int [] hand = {cardA, cardB};


    public CreateHand(int [] hand1, int dCard){

    hand = hand1;
    dealersCard = dCard;

    }


    public CreateHand Start(){

    CreateHand hand = new CreateHand(hand [],dealersCard); // hand [] has a syntax error!

    code continues .......




    iv tired 'hand' , '[] hand' and 'hand[]'..... any ideas where i am going wrong?

    Many Thanks

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,812
    Rep Power
    25

    Default Re: Creating an object containing an array and int - small error

    You don't use the type of a variable when using that variable as an argument to a method. Just use the name of the variable: hand
    leave off the []s

  3. #3
    treeface99 is offline Member
    Join Date
    Jan 2012
    Posts
    12
    Rep Power
    0

    Default Re: Creating an object containing an array and int - small error

    thanks for that. I tried 'hand' on its own but it still didn't like it. I played around with it a bit and found that the object was also called 'hand' and they couldn't be the called the same name.

    Thanks for your help

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,812
    Rep Power
    25

    Default Re: Creating an object containing an array and int - small error

    Is it working now?

Similar Threads

  1. Replies: 9
    Last Post: 07-29-2011, 03:18 PM
  2. Trouble creating object that includes array
    By Desdenova in forum New To Java
    Replies: 7
    Last Post: 05-18-2010, 08:33 PM
  3. small error
    By ayoood in forum New To Java
    Replies: 23
    Last Post: 05-27-2008, 01:18 PM
  4. Need help with creating array of type object
    By riz618 in forum New To Java
    Replies: 3
    Last Post: 01-29-2008, 07:14 AM
  5. Creating object of Type Object class
    By venkatv in forum New To Java
    Replies: 3
    Last Post: 07-17-2007, 04:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •