Я пишу эту маленькую заявку на участие в лотерее.
Теперь план состоит в том, чтобы посчитать, как часто каждый номер выпадал во время каждой итерации лотереи, и сохранить это где-нибудь.
Я предполагаю, что мне нужно будет использовать HashMap, который имеет 6 ключей и увеличивает значение на единицу каждый раз, когда рисуется соответствующий номер ключа.
Но как мне это сделать?
Мой код пока:
public void numberCreator()
{
// creating and initializing a Random generator
Random rand = new Random();
// A HashMap to store the numbers picked.
HashMap hashMap = new HashMap();
// A TreeMap to sort the numbers picked.
TreeMap treeMap = new TreeMap();
// creating an ArrayList which will store the pool of availbale Numbers
List<Integer>numPool = new ArrayList<Integer>();
for (int i=1; i<50; i++){
// add the available Numbers to the pool
numPool.add(i);
hashMap.put(nums[i], 0);
}
// array to store the lotto numbers
int [] nums = new int [6];
for (int i =0; i < nums.length; i++){
int numPoolIndex = rand.nextInt(numPool.size());
nums[i] = numPool.get(numPoolIndex);
// check how often a number has been called and store the new amount in the Map
int counter = hashMap.get
numPool.remove(numPoolIndex);
}
System.out.println(Arrays.toString(nums));
}
Может быть, кто-то может сказать мне, если у меня есть правильная идея, или даже как я бы правильно реализовал карту?