-1

I am attempting to write a 3 card poker game and have ran into a " The type of the expression must be an array type but it resolved to int" error that I am baffled by. The error does not seem to like the way I have done my counters but I am pretty new at coding and do not understand what the error is saying. If I had to guess I would say its my methods but I am pretty clueless when it comes to java. There are 3 spots below that I am getting the error. I have included the portion giving me trouble and the the whole set of code below it. Any help is appreciated.

     //This method will determine if the player has a pair
     public static int pair(String main)
     {
         int check = 0;
         int card1;
         int card2;

         for(int counter = 1; counter <3; counter++) //error here
         {
             if (card1[counter - 1] == card2[counter])
             {
                 check++;
             }
         }
         if (check == 1)
         {
             return 1;
         }
         else
         {
             return 0;
         }

     }

     //This method will tell the player if he has a high card
     public static int highcard(String main)
     {
         int highcard = 0;
         int card1;
         int card2;

         for (int counter = 0; counter < 3; counter++)
         {
             if (card1[counter] > highcard) // error here
             {
                 highcard = card1[counter]; // error here
             }
         }
         return highcard;    
     }

Here is the whole set of code

public static void main(String[] args) {
    Scanner in=new Scanner(System.in);
    //Setting variables 
    int card1;
    int card2;
    int card3;
    int faceValue1;
    int faceValue2;
    int faceValue3;
    int suit1;
    int suit2;
    int suit3;
    int suit4;


    Random g = new Random();

     card1 = g.nextInt(51)+1;
     card2 = g.nextInt(51)+1;
     card3 = g.nextInt(51)+1;
     suit1 = g.nextInt(3)+1;
     suit2 = g.nextInt(3)+1;
     suit3 = g.nextInt(3)+1;
     suit4 = g.nextInt(3)+1;
}
    public static String FaceValue(String main){
   //Making the players hand
     int card1;
     int card2;
     int card3;
     int faceValue1;
     int faceValue2;
     int faceValue3;
     int suit;
     int suit1;
     int suit2;
     int suit3;
     int suit4;

     faceValue1 = card1 /4 + 2;
     faceValue2 = card2 / 4 + 2;
     faceValue3 = card3 /4 + 2;
     System.out.println(faceValue1);
     System.out.println(faceValue2);
     System.out.println(faceValue3);    }
      //setting up a method to convert the cards and suit to a string
     public static String convert(String main){
         int card1;
         int card2;
         int card3;
         int faceValue1;
         int faceValue2;
         int faceValue3;
         int suit;
         int suit1;
         int suit2;
         int suit3;
         int suit4;
         suit = card1 % 4;

//Converting card and suit 1
         if (faceValue1 == 1)
                {
                    System.out.print("Ace of ");
                }
                if (faceValue1 == 2)
                {
                    System.out.print("Two of ");
                }
                if (faceValue1 == 3)
                {
                    System.out.print("Three of ");
                }
                if (faceValue1 == 4)
                {
                    System.out.print("Four of ");
                }
                if (faceValue1 == 5)
                {
                    System.out.print("Five of ");
                }
                if (faceValue1 == 6)
                {
                    System.out.print("Six of ");
                }
                if (faceValue1 == 7)
                {
                    System.out.print("Seven of ");
                }
                if (faceValue1 == 8)
                {
                    System.out.print("Eight of ");
                }
                if (faceValue1 == 9)
                {
                    System.out.print("Nine of ");
                }
                if (faceValue1 == 10)
                {
                    System.out.print("Ten of ");
                }
                if (faceValue1 == 11)
                {
                    System.out.print("Jack of ");
                }
                if (faceValue1 == 12)
                {
                    System.out.print("Queen of ");
                }
                if (faceValue1 == 13)
                {
                    System.out.print("King of ");
                }

                if (suit1 == 1)
                {
                    System.out.print("Spades");
                    System.out.println();
                }
                if (suit1 == 2)
                {
                    System.out.print("Hearts");
                    System.out.println();
                }
                if (suit1 == 3)
                {
                    System.out.print("Diamonds");
                    System.out.println();
                }
                if (suit1 == 4)
                {
                    System.out.print("Clubs");
                    System.out.println();
                }

                //Converting card and suit 2

                if (faceValue2 == 1)
                {
                    System.out.print("Ace of ");
                }
                if (faceValue2 == 2)
                {
                    System.out.print("Two of ");
                }
                if (faceValue2 == 3)
                {
                    System.out.print("Three of ");
                }
                if (faceValue2 == 4)
                {
                    System.out.print("Four of ");
                }
                if (faceValue2 == 5)
                {
                    System.out.print("Five of ");
                }
                if (faceValue2 == 6)
                {
                    System.out.print("Six of ");
                }
                if (faceValue2 == 7)
                {
                    System.out.print("Seven of ");
                }
                if (faceValue2 == 8)
                {
                    System.out.print("Eight of ");
                }
                if (faceValue2 == 9)
                {
                    System.out.print("Nine of ");
                }
                if (faceValue2 == 10)
                {
                    System.out.print("Ten of ");
                }
                if (faceValue2 == 11)
                {
                    System.out.print("Jack of ");
                }
                if (faceValue2 == 12)
                {
                    System.out.print("Queen of ");
                }
                if (faceValue2 == 13)
                {
                    System.out.print("King of ");
                }

                if (suit2 == 1)
                {
                    System.out.print("Spades");
                    System.out.println();
                }
                if (suit2 == 2)
                {
                    System.out.print("Hearts");
                    System.out.println();
                }
                if (suit2 == 3)
                {
                    System.out.print("Diamonds");
                    System.out.println();
                }
                if (suit2 == 4)
                {
                    System.out.print("Clubs");
                    System.out.println();
                }

     // Converting card and suit 3                  
                if (faceValue3 == 1)
                {
                    System.out.print("Ace of ");
                }
                if (faceValue3 == 2)
                {
                    System.out.print("Two of ");
                }
                if (faceValue3 == 3)
                {
                    System.out.print("Three of ");
                }
                if (faceValue3 == 4)
                {
                    System.out.print("Four of ");
                }
                if (faceValue3 == 5)
                {
                    System.out.print("Five of ");
                }
                if (faceValue3 == 6)
                {
                    System.out.print("Six of ");
                }
                if (faceValue3 == 7)
                {
                    System.out.print("Seven of ");
                }
                if (faceValue3 == 8)
                {
                    System.out.print("Eight of ");
                }
                if (faceValue3 == 9)
                {
                    System.out.print("Nine of ");
                }
                if (faceValue3 == 10)
                {
                    System.out.print("Ten of ");
                }
                if (faceValue3 == 11)
                {
                    System.out.print("Jack of ");
                }
                if (faceValue3 == 12)
                {
                    System.out.print("Queen of ");
                }
                if (faceValue3 == 13)
                {
                    System.out.print("King of ");
                }

                if (suit3 == 1)
                {
                    System.out.print("Spades");
                    System.out.println();
                }
                if (suit3 == 2)
                {
                    System.out.print("Hearts");
                    System.out.println();
                }
                if (suit3 == 3)
                {
                    System.out.print("Diamonds");
                    System.out.println();
                }
                if (suit3 == 4)
                {
                    System.out.print("Clubs");
                    System.out.println();
                }
                System.out.println("Your hand is " + faceValue1 + suit1 +"," + faceValue2 + suit2 + "," + faceValue3 + suit3);
                }

     //This method will determine if the player has a flush
     public static int flush(String main)
     {
         int suit2;
         int suit1;

     for (int counter = 1; counter < 3; counter++)
     {
         if (suit1 != suit2)
         {
             return 1;
         }
     }
     return 0;

     }

     //This method will determine if the player has a straight
     public static int straight(String main)
     {
         int card1;
         int card2;

        for (int counter2 = 1; counter2 < 3; counter2++)
            if (card1[counter2 - 1] != (card2[counter2] - 1))
            {
                return 1;
            }

     return 1;

     }
     //This method will determine if the player has three of a kind
     public static int threekind(String main)
     {
         int card1;
         int card2;
         int card3;
         if (card1 == card2 && card2 == card3)
         {
             return 1;
         }
         return 0;
     }

     //This method will determine if the player has a pair
     public static int pair(String main)
     {
         int check = 0;
         int card1;
         int card2;

         for(int counter = 1; counter <3; counter++)
         {
             if (card1[counter - 1] == card2[counter])
             {
                 check++;
             }
         }
         if (check == 1)
         {
             return 1;
         }
         else
         {
             return 0;
         }

     }

     //This method will tell the player if he has a high card
     public static int highcard(String main)
     {
         int highcard = 0;
         int card1;
         int card2;

         for (int counter = 0; counter < 3; counter++)
         {
             if (card1[counter] > highcard)
             {
                 highcard = card1[counter];
             }
         }
         return highcard;    
     }

                /* This method will evaluates the hand and see what the player has
                and give the player an output of their hand*/
                public static int evaluate(String main)
                {

                 if (flush() == 1)
                {
                    System.out.println("You have a flush!");
                }
                else if (straight() == 1)
                {
                    System.out.println("You have a straight!");
                }
                else if (threekind() == 1)
                {
                    System.out.println("You have a three of a kind!");
                }

                else if (pair() == 1)
                {
                    System.out.println("You have a pair!");
                }
                else
                {
                    int highCard = highCard();
                    System.out.println("Your highest card is " + highCard);
                }
            }
     }
     }}
Sam
  • 31
  • 3

2 Answers2

0

I think this line can not throw such an error

for(int counter = 1; counter <3; counter++)

But these three definately will have issue

if (card1[counter - 1] == card2[counter])
...
if (card1[counter] > highcard) // error here
             {
                 highcard = card1[counter]; // error here

because you making an attempt to iterate over card1 and card2, which are ints, but not arrays

Bogdan
  • 310
  • 6
  • 12
0

In all three of those cases, card1 and card2 are not arrays. They are straight ints. And subscripting an int doesn't make sense (what does it even mean?).

Joe C
  • 15,324
  • 8
  • 38
  • 50