So I'm currently trying to use an array with my program and have it add 1 every time a value is within a set range.
/** Imports **/
import java.util.Scanner;
import java.util.Random;
/** Main code **/
public class DropRate2
{
public static void main(String[] args)
{
double min, max;
min = 0;
max = 1;
Scanner scan = new Scanner(System.in);
System.out.println("Enter a case type:");
String userinput = scan.nextLine();
Random rand = new Random();
int Drops[] = {1, 2, 3, 4, 5};
/** SHADOW **/
if (userinput.equalsIgnoreCase("Shadow"))
{
System.out.println("You chose the " + userinput + " case.\n");
System.out.println("How many cases do you wish to open?");
int loops = scan.nextInt();
System.out.println("Opening " + loops + " cases!");
for (int i = 0; i < loops; i++)
{
double chance = min + (max - min) * rand.nextDouble();
if (chance >= .769)
Drops[0] ++;
else if (chance >= .0259 && chance <= .758)
Drops[1] ++;
else if (chance >= .0169 && chance <= .258)
Drops[2] ++;
else if (chance >= .0089 && chance <= .0168)
Drops[3] ++;
else if (chance >= 0 && chance <= .0088)
Drops[4] ++;
}
System.out.println("You got " + Drops[0] + " blues.");
System.out.println("You got " + Drops[1] + " purples.");
System.out.println("You got " + Drops[2] + " pinks.");
System.out.println("You got " + Drops[3] + " reds.");
System.out.println("You got " + Drops[4] + " yellows.");
}
}
There is also a final brace to close the class itself, just didn't format it on here some reason
I'm unsure where the issue even lies at this point. I'm unsure if the issue is in the array itself, or in the rest of the code. When I run this only ONE of the array groups should go up an increment. This way that if I open 10 for example, there should only be 10 total, spread throughout based on the chance. When I ran this I got many in each, eg 5 in purple, 8 in yellow, etc.
Drops[x]++will do what you want it to.double chance = rand.nextDouble();instead. Also sometimes none of the numbers in the array will be increased. e.g. If chance is .7585