java - Arrays, algorithms and elements -


i trying make poker game through java. first thing wanted distribute 5 cards using arrays. have done distribution part, how can prevent same cards being distributed twice. in other words, how can check if array contains element. want able detect if element exists in array, , if does, want able change card has been given out twice, appreciated. codes down below,

      import java.util.random;       import java.util.scanner;       import java.util.arrays;       public class poker     {         public final static string[] numbers = {"❤","♠","♦","♣"};           public final static string[] sign = {"1","2","3","4","5","6","7","8","10","j","q","k","a"};         private string[] hand = {"","","","",""};         private boolean found;         private random random;         public poker()          {             found = false;            string hand[] = {"","","","",""};            int tokens = 10;             scanner in = new scanner(system.in);            random = new random();         }         public void handout()         {             (int = 0; < 5; i++)            {                int numberrandom = random.nextint(numbers.length);                int signrandom = random.nextint(sign.length);                string pickednumber = numbers[numberrandom];                string pickedsign = sign[signrandom];                string combinedsigns = pickedsign + pickednumber;                hand[i] = combinedsigns;            system.out.print(hand[i] + " ");         }         system.out.println("\n");     }    } 

what want break code different methods. should have method generating 1 card, method checking whether or not card in hand, , method distribute cards hand.

public string generatecard() {     int numberrandom = random.nextint(numbers.length);     int signrandom = random.nextint(sign.length);     string pickednumber = numbers[numberrandom];     string pickedsign = sign[signrandom];     return pickedsign + pickednumber; }  public static boolean cardisinhand(string card) {     for(int = 0; < 5; i++) {         if(hand[i] != null && hand[i].contains(card)) {             return true;         }     }      return false; }  public static void handout() {     (int = 0; < 5; i++) {         string card = generatecard();          while(cardisinhand(card)) {             card = generatecard();         }          hand[i] = card;     } } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -