SHARE
TWEET

Untitled

a guest Nov 16th, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3. import java.util.Random;
  4.  
  5. public class roller{
  6.  
  7.     public static int roll(int x){
  8.         int sides = x;
  9.         Random rand = new Random();
  10.         int rolled = rand.nextInt(sides)+1;
  11.  
  12.         return rolled;
  13.  
  14.     }
  15.  
  16.    
  17.     public static void main(String[] args){
  18.  
  19.         Scanner in = new Scanner(System.in);
  20.         char ch;
  21.  
  22.         do{
  23.             int diceSides = 0;
  24.             int sum = 0;
  25.              System.out.println("**Welcome to the Dice Roll Stats Calculator!**");
  26.             System.out.println("Please enter the number of dice you would like to roll from 1-6.");
  27.  
  28.             int diceToRoll = in.nextInt();
  29.  
  30.             for (int x = 0; x < diceToRoll; x++){
  31.                 System.out.println("Please enter the number of sides on your die from 1-6: ");
  32.                 diceSides = in.nextInt();
  33.                 System.out.println("You entered " + diceSides);
  34.                 int rolled = roll(diceSides);
  35.                 System.out.println("You rolled: " + rolled);
  36.                 sum = sum + rolled;
  37.                  if (rolled == 1) {
  38.         System.out.println("Ouch");
  39. }
  40. else if (rolled == 2) {
  41.         System.out.println("Ehhh");    
  42. }
  43.   else if (rolled == 3) {
  44.         System.out.println("Not too shabby");
  45.        
  46. }  
  47.   else if (rolled == 4) {
  48.         System.out.println("Oooo Almost Good");
  49.        
  50.  }  
  51.   else if (rolled == 5) {
  52.         System.out.println("Hey, Thats Pretty Good!");  
  53.  }  
  54.   else if (rolled == 6) {
  55.         System.out.println("Oh Yeahhh!");    
  56. }          
  57.    
  58.            
  59.             }
  60.  
  61.             System.out.println("Total of the dice rolled = " + sum);
  62.  
  63.             System.out.println("If Done simply type 'x' or another number to continue ");
  64.             ch=(char)in.next().charAt(0);
  65.  
  66.         }while(ch!='x');
  67.     }
  68. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top