HughesElite

Untitled

May 18th, 2021
561
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         scan.close();
  32.  
  33.        
  34.         while (rollTotal != 3)
  35.         {
  36.             int diceOneRoll = rand.nextInt(diceOneInt) +1;
  37.             diceResults.add(diceOneRoll);
  38.            
  39.             int diceTwoRoll = rand.nextInt (diceTwoInt) +1;
  40.             diceResults.add(diceTwoRoll);
  41.             rollTotal++;
  42.         }
  43.    
  44.         System.out.print("Dice 1 rolls " + (diceResults.get(0)));
  45.         System.out.print(", " + (diceResults.get(2)));
  46.         System.out.print(", " + (diceResults.get(4)));
  47.        
  48.         System.out.print("\nDice 2 rolls " + (diceResults.get(1)));
  49.         System.out.print(", " + (diceResults.get(3)));
  50.         System.out.print(", " + (diceResults.get(5)));
  51.        
  52.         System.out.print("\nDice one rolls a total of ");
  53.         System.out.print(diceResults.get(0) + (diceResults.get(2) + diceResults.get(4)));
  54.        
  55.         System.out.print("\nDice two rolls a total of ");
  56.         System.out.print(diceResults.get(1) + (diceResults.get(3) + diceResults.get(5)));
  57.        
  58.         System.out.print("\nDice one rolls an average of ");
  59.         System.out.print((diceResults.get(0) + (diceResults.get(2) + diceResults.get(4))) /3.0);
  60.        
  61.         System.out.print("\nDice two rolls an average of ");
  62.         System.out.print((diceResults.get(1) + (diceResults.get(3) + diceResults.get(5))) /3.0);
  63.         }
  64.     }
  65. }
RAW Paste Data