Advertisement
HughesElite

Untitled

May 18th, 2021
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Random;
  5. import java.util.InputMismatchException;
  6. public class ConfigTestArea
  7. {
  8.     public static void main(String[] args)
  9.     {
  10.         ConfigTestArea Obj = new ConfigTestArea();
  11.         Obj.go();
  12.  
  13.     }
  14.    
  15.     public void go()
  16.     {
  17.         Scanner scan = new Scanner(System.in);
  18.         Random rand = new Random();
  19.         int diceOneInt;
  20.         int diceTwoInt;
  21.         int rollTotal = 0;
  22.         List<Integer> diceResults = new ArrayList<Integer>();
  23.        
  24.         try {
  25.        
  26.         System.out.println("How many sides does the first dice have?");
  27.         diceOneInt = scan.nextInt();
  28.        
  29.         System.out.println("How many sides does the second dice have?");
  30.         diceTwoInt = scan.nextInt();
  31.             } catch (InputMismatchException e) {
  32.                 System.out.println("no");
  33.                
  34.            
  35.        
  36.        
  37.         scan.close();
  38.        
  39.         while (rollTotal != 3)
  40.         {
  41.             int diceOneRoll = rand.nextInt(diceOneInt) +1;
  42.             diceResults.add(diceOneRoll);
  43.            
  44.             int diceTwoRoll = rand.nextInt (diceTwoInt) +1;
  45.             diceResults.add(diceTwoRoll);
  46.             rollTotal++;
  47.         }
  48.    
  49.         System.out.print("Dice 1 rolls " + (diceResults.get(0)));
  50.         System.out.print(", " + (diceResults.get(2)));
  51.         System.out.print(", " + (diceResults.get(4)));
  52.        
  53.         System.out.print("\nDice 2 rolls " + (diceResults.get(1)));
  54.         System.out.print(", " + (diceResults.get(3)));
  55.         System.out.print(", " + (diceResults.get(5)));
  56.        
  57.         System.out.print("\nDice one rolls a total of ");
  58.         System.out.print(diceResults.get(0) + (diceResults.get(2) + diceResults.get(4)));
  59.        
  60.         System.out.print("\nDice two rolls a total of ");
  61.         System.out.print(diceResults.get(1) + (diceResults.get(3) + diceResults.get(5)));
  62.        
  63.         System.out.print("\nDice one rolls an average of ");
  64.         System.out.print((diceResults.get(0) + (diceResults.get(2) + diceResults.get(4))) /3.0);
  65.        
  66.         System.out.print("\nDice two rolls an average of ");
  67.         System.out.print((diceResults.get(1) + (diceResults.get(3) + diceResults.get(5))) /3.0);
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement