Write a program that simulate a die roller. The user should type in the number of the throws.
Let the program count how many ones, twos, threes... are in the series.
In the end the program should write down how many ones ... that was and also figure out the percentage. I wrote a program but it doesn´t work. Please help.
package inlamning;
import java.text.NumberFormat; // import numberformat för att få svaret bara med en decimal
import javax.swing.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
String s;
s = JOptionPane.showInputDialog("Ange antal kast");
int k = Integer.parseInt(s); // Omvandla k till int
int summan = 0; // Ange att summan i snurran är lika med 0
int a = 0; //Ange att a - f är lika med noll och omvandlas till int
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
while (summan >= k){
Random diceRoller = new Random();
int dice = diceRoller.nextInt(6) + 1;
if (dice==1)
a =a+1;
else if (dice==2)
b = b+1;
else if (dice==3)
c = c+1;
else if (dice==4)
d = d+1;
else if (dice==5)
e = e+1;
else if (dice==6)
f = f+1;
summan = summan ++;
}
NumberFormat r = NumberFormat.getInstance();
double ettor = a/k * 100;
double tvaor = b/k * 100;
double treor = c/k * 100;
double fyror = d/k * 100;
double femmor = e/k * 100;
double sexor = f/k * 100;
r.setMaximumFractionDigits(1);
JOptionPane.showMessageDialog(null, "Du har kastat tärningen" + k + "gånger"
+ "Du har fått en etta " + a + " gånger. dvs " + ettor + "%"
+ "Du har fått en tvåa " + b + " gånger. dvs " + tvaor + "%"
+"Du har fått en trea " + c + " gånger. dvs " + treor + "%"
+"Du har fått en fyra " + d + " gånger. dvs " + fyror + "%"
+"Du har fått en femma " + e + " gånger. dvs " + femmor + "%"
+"Du har fått en sexa " + f + " gånger. dvs " + sexor + "%");
}
}