So i am kinda new to java and i need help with a problem.
I have this code:
import java.util.Random;
public class Board
{
private int NumberOfCards;
private int NumberOfPairs;
private int[] DeckOfCards;
private int CardsRemaining;
public Board(int NumberOfPairs){
this.NumberOfCards = NumberOfCards;
this.NumberOfPairs = NumberOfPairs;
this.CardsRemaining = CardsRemaining;
DeckOfCards = new int [2*NumberOfPairs];
Random numbers = new Random();
for (int i = 0; i < NumberOfPairs; i++) {
DeckOfCards[i] = numbers.nextInt();
}
The code above is not completed and there are many classes left to be completed but the
problem is that:
Lets say that NumberOfPairs = 3
This will mean that inside the array we will have the numbers 0,1,2 with random positions and this will also mean that we will have 3 positions of the array "empty" (because the size is 2*NumberOfPairs)
What i am trying to do is for example this:
Inside the array will still be the numbers 0,1,2 but twice and with random order such as:
1,0,2,2,1,0
Does anyone have any ideas ? Thank you in advance!
Oh yes i forgot to mention that the NumberOfPairs is not certain and will be given by the user via input
0 0 1 1 2 2or0 1 2 0 1 2, then shuffle it.