The computer should randomly select 1 of 4 words: (HEARTS, DIAMONDS, CLUBS, SPADES)
1000 times.
Print out the statistics of the percentage of time each word was chosen.
import java.util.Scanner;
import java.util.Random;
public class QuestionFive {
public static void main(String[] args) {
int result;
int hnum =0, cnum, dnum, snum;
Scanner scan = new Scanner(System.in);
for (int i = 0; i < 1000; i += 1) {
// generate a random numbr between 0 - 3
Random r = new Random();
result = r.nextInt(4);
System.out.println(result);
// if the random number is zero assume it is hearts.
if (result == 1) {
System.out.println(i + " You drew Hearts");
hnum = hnum + 1;
}
// else if the random number is 1 assume it is clubs
else if (result = "CLUBS")
cnum = cnum + 1;
else if (result = "DIAMONDS")
dnum = dnum + 1;
else if (result = "SPADES")
snum = snum + 1*/;
}
System.out.println("The chances of getting HEARTS is " + (hnum / 1000.00) * 100 + "%");
System.out.println("The chances of getting CLUBS is " + (cnum / 1000) * 100 + "%");
System.out.println("The chances of getting DIAMONDS is " + (dnum / 1000) * 100 + "%");
System.out.println("The chances of getting SPADES is " + (snum / 1000) * 100 + "%")*/;
}
}