import java.util.Scanner; import java.util.ArrayList; public class dndDice { public static int end = 0; public static void quit(){ System.out.println("Quitting..."); end = 1; } public static ArrayList diceChoice(String diceType, int diceAmount) { ArrayList result = new ArrayList (); for (int i = diceAmount; i > 0; i--) { switch(diceType){ case "coin": int d2 = (int)(Math.random() * 2) +1; if (d2 == 1){ result.add("Heads"); } else { result.add("Tails"); } break; case "d4": int d4 = (int)(Math.random() * 4) +1; String d4result = Integer.toString(d4); result.add(d4result); break; case "d6": int d6 = (int)(Math.random() * 6) +1; String d6result = Integer.toString(d6); result.add(d6result); break; case "d10": int d10 = (int)(Math.random() * 10) +1; String d10result = Integer.toString(d10); result.add(d10result); break; case "d%": int dperc = (int)(Math.random() * 100) +1; String dpercresult = Integer.toString(dperc); result.add(dpercresult); break; case "d8": int d8 = (int)(Math.random() * 8) +1; String d8result = Integer.toString(d8); result.add(d8result); break; case "d12": int d12 = (int)(Math.random() * 12) +1; String d12result = Integer.toString(d12); result.add(d12result); break; case "d20": int d20 = (int)(Math.random() * 20) +1; String d20result = Integer.toString(d20); result.add(d20result); break; default: result.add("Dice Type not found. Supported Dice Types are: coin, d4, d6, d8, d10, d%, d12, d20."); return result; } } return result; } public static void main(String[] args) { Scanner userInput = new Scanner(System.in); for (int i = end; i == 0; i = end) { System.out.println("Select dice type. Type \"Quit\" to quit:"); String diceType = userInput.nextLine(); if (diceType.equals("Quit")){ userInput.close(); quit(); } else { System.out.println("Select amount:"); int diceAmount = userInput.nextInt(); userInput.nextLine(); System.out.println("Your results are: " + diceChoice(diceType, diceAmount)); } } } }