Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- import java.util.Random;
- public class roller{
- public static int roll(int x){
- int sides = x;
- Random rand = new Random();
- int rolled = rand.nextInt(sides)+1;
- return rolled;
- }
- public static void main(String[] args){
- Scanner in = new Scanner(System.in);
- char ch;
- do{
- int diceSides = 0;
- int sum = 0;
- System.out.println("**Welcome to the Dice Roll Stats Calculator!**");
- System.out.println("Please enter the number of dice you would like to roll from 1-6.");
- int diceToRoll = in.nextInt();
- for (int x = 0; x < diceToRoll; x++){
- System.out.println("Please enter the number of sides on your die from 1-6: ");
- diceSides = in.nextInt();
- System.out.println("You entered " + diceSides);
- int rolled = roll(diceSides);
- System.out.println("You rolled: " + rolled);
- sum = sum + rolled;
- if (rolled == 1) {
- System.out.println("Ouch");
- }
- else if (rolled == 2) {
- System.out.println("Ehhh");
- }
- else if (rolled == 3) {
- System.out.println("Not too shabby");
- }
- else if (rolled == 4) {
- System.out.println("Oooo Almost Good");
- }
- else if (rolled == 5) {
- System.out.println("Hey, Thats Pretty Good!");
- }
- else if (rolled == 6) {
- System.out.println("Oh Yeahhh!");
- }
- }
- System.out.println("Total of the dice rolled = " + sum);
- System.out.println("If Done simply type 'x' or another number to continue ");
- ch=(char)in.next().charAt(0);
- }while(ch!='x');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement