Advertisement
Guest User

DieRoller

a guest
Aug 30th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 17.07 KB | None | 0 0
  1. package dieroller;
  2.  
  3. import javax.swing.JOptionPane;
  4.  
  5. /**33
  6.  *
  7.  * @author Conor
  8.  */
  9. public class DieRoller {
  10.  
  11.     /**
  12.      * @param args the command line arguments
  13.      */
  14.     public static void main(String[] args) {
  15.         String input1;
  16.     String input2;
  17.         double result1 = 0;
  18.         double result2 = 0;
  19.     double result3 = 0;
  20.     double result4 = 0;
  21.     double result5 = 0;
  22.     double result6 = 0;
  23.         double sum;
  24.    
  25.         for(int i=0; i <5; i++){
  26.     input1 = JOptionPane.showInputDialog("Enter in the amount of die you would like to roll:");
  27.         input2 = JOptionPane.showInputDialog("Enter in the amount of sides on the die:");
  28.           switch(input1){
  29.            case "1":
  30.           switch (input2) {
  31.                 case "100":
  32.                     result1 = Math.floor((Math.random()*100)+1);
  33.                     break;
  34.                 case "2":
  35.                     result1 = Math.floor((Math.random()*2)+1);
  36.                     break;
  37.                 case "3":
  38.                     result1 = Math.floor((Math.random()*3)+1);
  39.                     break;
  40.                 case "4":
  41.                     result1 = Math.floor((Math.random()*4)+1);
  42.                     break;
  43.                 case "5":
  44.                     result1 = Math.floor((Math.random()*5)+1);
  45.                     break;
  46.                 case "6":
  47.                     result1 = Math.floor((Math.random()*6)+1);
  48.                     break;
  49.                 case "8":
  50.                     result1 = Math.floor((Math.random()*8)+1);
  51.                     break;
  52.                 case "10":
  53.                     result1 = Math.floor((Math.random()*10)+1);
  54.                     break;
  55.                 case "12":
  56.                     result1 = Math.floor((Math.random()*12)+1);
  57.                     break;
  58.                 case "20":
  59.                     result1 = Math.floor((Math.random()*20)+1);
  60.                     break;
  61.             }
  62.             break;
  63.             case "2":
  64.             switch (input2) {
  65.                 case "100":
  66.                     result1 = Math.floor((Math.random()*100)+1);
  67.                     result2 = Math.floor((Math.random()*100)+1);
  68.                     break;
  69.                 case "2":
  70.                     result1 = Math.floor((Math.random()*2)+1);
  71.                     result2 = Math.floor((Math.random()*2)+1);
  72.                     break;
  73.                 case "3":
  74.                     result1 = Math.floor((Math.random()*3)+1);
  75.                     result2 = Math.floor((Math.random()*3)+1);
  76.                     break;
  77.                 case "4":
  78.                     result1 = Math.floor((Math.random()*4)+1);
  79.                     result2 = Math.floor((Math.random()*4)+1);
  80.                     break;
  81.                 case "5":
  82.                     result1 = Math.floor((Math.random()*5)+1);
  83.                     result2 = Math.floor((Math.random()*5)+1);
  84.                     break;
  85.                 case "6":
  86.                     result1 = Math.floor((Math.random()*6)+1);
  87.                     result2 = Math.floor((Math.random()*6)+1);
  88.                     break;
  89.                 case "8":
  90.                     result1 = Math.floor((Math.random()*8)+1);
  91.                     result2 = Math.floor((Math.random()*8)+1);
  92.                     break;
  93.                 case "10":
  94.                     result1 = Math.floor((Math.random()*10)+1);
  95.                     result2 = Math.floor((Math.random()*10)+1);
  96.                     break;
  97.                 case "12":
  98.                     result1 = Math.floor((Math.random()*12)+1);
  99.                     result2 = Math.floor((Math.random()*12)+1);
  100.                     break;
  101.                 case "20":
  102.                     result1 = Math.floor((Math.random()*20)+1);
  103.                     result2 = Math.floor((Math.random()*20)+1);
  104.                     break;
  105.                     }
  106.                     break;
  107.                 case "3":
  108.                 switch (input2) {
  109.                 case "100":
  110.                     result1 = Math.floor((Math.random()*100)+1);
  111.                     result2 = Math.floor((Math.random()*100)+1);
  112.                     result3 = Math.floor((Math.random()*100)+1);
  113.                     break;
  114.                 case "2":
  115.                     result1 = Math.floor((Math.random()*2)+1);
  116.                     result2 = Math.floor((Math.random()*2)+1);
  117.                     result3 = Math.floor((Math.random()*2)+1);
  118.                     break;
  119.                 case "3":
  120.                     result1 = Math.floor((Math.random()*3)+1);
  121.                     result2 = Math.floor((Math.random()*3)+1);
  122.                     result3 = Math.floor((Math.random()*3)+1);
  123.                     break;
  124.                 case "4":
  125.                     result1 = Math.floor((Math.random()*4)+1);
  126.                     result2 = Math.floor((Math.random()*4)+1);
  127.                     result3 = Math.floor((Math.random()*4)+1);
  128.                     break;
  129.                 case "5":
  130.                     result1 = Math.floor((Math.random()*5)+1);
  131.                     result2 = Math.floor((Math.random()*5)+1);
  132.                     result3 = Math.floor((Math.random()*5)+1);
  133.                     break;
  134.                 case "6":
  135.                     result1 = Math.floor((Math.random()*6)+1);
  136.                     result2 = Math.floor((Math.random()*6)+1);
  137.                     result3 = Math.floor((Math.random()*6)+1);
  138.                     break;
  139.                 case "8":
  140.                     result1 = Math.floor((Math.random()*8)+1);
  141.                     result2 = Math.floor((Math.random()*8)+1);
  142.                     result3 = Math.floor((Math.random()*8)+1);
  143.                     break;
  144.                 case "10":
  145.                     result1 = Math.floor((Math.random()*10)+1);
  146.                     result2 = Math.floor((Math.random()*10)+1);
  147.                     result3 = Math.floor((Math.random()*10)+1);
  148.                     break;
  149.                 case "12":
  150.                     result1 = Math.floor((Math.random()*12)+1);
  151.                     result2 = Math.floor((Math.random()*12)+1);
  152.                     result3 = Math.floor((Math.random()*12)+1);
  153.                     break;
  154.                 case "20":
  155.                     result1 = Math.floor((Math.random()*20)+1);
  156.                     result2 = Math.floor((Math.random()*20)+1);
  157.                     result3 = Math.floor((Math.random()*20)+1);
  158.                     break;
  159.                     }
  160.                 case "4":
  161.                 switch (input2) {
  162.                 case "100":
  163.                     result1 = Math.floor((Math.random()*100)+1);
  164.                     result2 = Math.floor((Math.random()*100)+1);
  165.                     result3 = Math.floor((Math.random()*100)+1);
  166.                     result4 = Math.floor((Math.random()*100)+1);
  167.                     break;
  168.                 case "2":
  169.                     result1 = Math.floor((Math.random()*2)+1);
  170.                     result2 = Math.floor((Math.random()*2)+1);
  171.                     result3 = Math.floor((Math.random()*2)+1);
  172.                     result4 = Math.floor((Math.random()*2)+1);
  173.                     break;
  174.                 case "3":
  175.                     result1 = Math.floor((Math.random()*3)+1);
  176.                     result2 = Math.floor((Math.random()*3)+1);
  177.                     result3 = Math.floor((Math.random()*3)+1);
  178.                     result4 = Math.floor((Math.random()*3)+1);
  179.                     break;
  180.                 case "4":
  181.                     result1 = Math.floor((Math.random()*4)+1);
  182.                     result2 = Math.floor((Math.random()*4)+1);
  183.                     result3 = Math.floor((Math.random()*4)+1);
  184.                     result4 = Math.floor((Math.random()*4)+1);
  185.                     break;
  186.                 case "5":
  187.                     result1 = Math.floor((Math.random()*5)+1);
  188.                     result2 = Math.floor((Math.random()*5)+1);
  189.                     result3 = Math.floor((Math.random()*5)+1);
  190.                     result4 = Math.floor((Math.random()*5)+1);
  191.                     break;
  192.                 case "6":
  193.                     result1 = Math.floor((Math.random()*6)+1);
  194.                     result2 = Math.floor((Math.random()*6)+1);
  195.                     result3 = Math.floor((Math.random()*6)+1);
  196.                     result4 = Math.floor((Math.random()*6)+1);
  197.                     break;
  198.                 case "8":
  199.                     result1 = Math.floor((Math.random()*8)+1);
  200.                     result2 = Math.floor((Math.random()*8)+1);
  201.                     result3 = Math.floor((Math.random()*8)+1);
  202.                     result4 = Math.floor((Math.random()*8)+1);
  203.                     break;
  204.                 case "10":
  205.                     result1 = Math.floor((Math.random()*10)+1);
  206.                     result2 = Math.floor((Math.random()*10)+1);
  207.                     result3 = Math.floor((Math.random()*10)+1);
  208.                     result4 = Math.floor((Math.random()*10)+1);
  209.                     break;
  210.                 case "12":
  211.                     result1 = Math.floor((Math.random()*12)+1);
  212.                     result2 = Math.floor((Math.random()*12)+1);
  213.                     result3 = Math.floor((Math.random()*12)+1);
  214.                     result4 = Math.floor((Math.random()*12)+1);
  215.                     break;
  216.                 case "20":
  217.                     result1 = Math.floor((Math.random()*20)+1);
  218.                     result2 = Math.floor((Math.random()*20)+1);
  219.                     result3 = Math.floor((Math.random()*20)+1);
  220.                     result4 = Math.floor((Math.random()*20)+1);
  221.                     break;
  222.                     }
  223.                     case "5":
  224.                     switch (input2) {
  225.                 case "100":
  226.                     result1 = Math.floor((Math.random()*100)+1);
  227.                     result2 = Math.floor((Math.random()*100)+1);
  228.                     result3 = Math.floor((Math.random()*100)+1);
  229.                     result4 = Math.floor((Math.random()*100)+1);
  230.                     result5 = Math.floor((Math.random()*100)+1);
  231.  
  232.                     break;
  233.                 case "2":
  234.                     result1 = Math.floor((Math.random()*2)+1);
  235.                     result2 = Math.floor((Math.random()*2)+1);
  236.                     result3 = Math.floor((Math.random()*2)+1);
  237.                     result4 = Math.floor((Math.random()*2)+1);
  238.                     result5 = Math.floor((Math.random()*2)+1);
  239.  
  240.                     break;
  241.                 case "3":
  242.                     result1 = Math.floor((Math.random()*3)+1);
  243.                     result2 = Math.floor((Math.random()*3)+1);
  244.                     result3 = Math.floor((Math.random()*3)+1);
  245.                     result4 = Math.floor((Math.random()*3)+1);
  246.                     result5 = Math.floor((Math.random()*3)+1);
  247.  
  248.                     break;
  249.                 case "4":
  250.                     result1 = Math.floor((Math.random()*4)+1);
  251.                     result2 = Math.floor((Math.random()*4)+1);
  252.                     result3 = Math.floor((Math.random()*4)+1);
  253.                     result4 = Math.floor((Math.random()*4)+1);
  254.                     result5 = Math.floor((Math.random()*4)+1);
  255.  
  256.                     break;
  257.                 case "5":
  258.                     result1 = Math.floor((Math.random()*5)+1);
  259.                     result2 = Math.floor((Math.random()*5)+1);
  260.                     result3 = Math.floor((Math.random()*5)+1);
  261.                     result4 = Math.floor((Math.random()*5)+1);
  262.                     result5 = Math.floor((Math.random()*5)+1);
  263.  
  264.                     break;
  265.                 case "6":
  266.                     result1 = Math.floor((Math.random()*6)+1);
  267.                     result2 = Math.floor((Math.random()*6)+1);
  268.                     result3 = Math.floor((Math.random()*6)+1);
  269.                     result4 = Math.floor((Math.random()*6)+1);
  270.                     result5 = Math.floor((Math.random()*6)+1);
  271.  
  272.                     break;
  273.                 case "8":
  274.                     result1 = Math.floor((Math.random()*8)+1);
  275.                     result2 = Math.floor((Math.random()*8)+1);
  276.                     result3 = Math.floor((Math.random()*8)+1);
  277.                     result4 = Math.floor((Math.random()*8)+1);
  278.                     result5 = Math.floor((Math.random()*8)+1);
  279.  
  280.                     break;
  281.                 case "10":
  282.                     result1 = Math.floor((Math.random()*10)+1);
  283.                     result2 = Math.floor((Math.random()*10)+1);
  284.                     result3 = Math.floor((Math.random()*10)+1);
  285.                     result4 = Math.floor((Math.random()*10)+1);
  286.                     result5 = Math.floor((Math.random()*10)+1);
  287.  
  288.                     break;
  289.                 case "12":
  290.                     result1 = Math.floor((Math.random()*12)+1);
  291.                     result2 = Math.floor((Math.random()*12)+1);
  292.                     result3 = Math.floor((Math.random()*12)+1);
  293.                     result4 = Math.floor((Math.random()*12)+1);
  294.                     result5 = Math.floor((Math.random()*12)+1);
  295.  
  296.                     break;
  297.                 case "20":
  298.                     result1 = Math.floor((Math.random()*20)+1);
  299.                     result2 = Math.floor((Math.random()*20)+1);
  300.                     result3 = Math.floor((Math.random()*20)+1);
  301.                     result4 = Math.floor((Math.random()*20)+1);
  302.                     result5 = Math.floor((Math.random()*20)+1);
  303.                     break;
  304.                     }
  305.                     case "6":
  306.                         switch (input2) {
  307.                 case "100":
  308.                     result1 = Math.floor((Math.random()*100)+1);
  309.                     result2 = Math.floor((Math.random()*100)+1);
  310.                     result3 = Math.floor((Math.random()*100)+1);
  311.                     result4 = Math.floor((Math.random()*100)+1);
  312.                     result5 = Math.floor((Math.random()*100)+1);
  313.                     result6 = Math.floor((Math.random()*100)+1);
  314.  
  315.                     break;
  316.                 case "2":
  317.                     result1 = Math.floor((Math.random()*2)+1);
  318.                     result2 = Math.floor((Math.random()*2)+1);
  319.                     result3 = Math.floor((Math.random()*2)+1);
  320.                     result4 = Math.floor((Math.random()*2)+1);
  321.                     result5 = Math.floor((Math.random()*2)+1);
  322.                     result6 = Math.floor((Math.random()*2)+1);
  323.  
  324.                     break;
  325.                 case "3":
  326.                     result1 = Math.floor((Math.random()*3)+1);
  327.                     result2 = Math.floor((Math.random()*3)+1);
  328.                     result3 = Math.floor((Math.random()*3)+1);
  329.                     result4 = Math.floor((Math.random()*3)+1);
  330.                     result5 = Math.floor((Math.random()*3)+1);
  331.                     result6 = Math.floor((Math.random()*3)+1);
  332.  
  333.                     break;
  334.                 case "4":
  335.                     result1 = Math.floor((Math.random()*4)+1);
  336.                     result2 = Math.floor((Math.random()*4)+1);
  337.                     result3 = Math.floor((Math.random()*4)+1);
  338.                     result4 = Math.floor((Math.random()*4)+1);
  339.                     result5 = Math.floor((Math.random()*4)+1);
  340.                     result6 = Math.floor((Math.random()*4)+1);
  341.  
  342.                     break;
  343.                 case "5":
  344.                     result1 = Math.floor((Math.random()*5)+1);
  345.                     result2 = Math.floor((Math.random()*5)+1);
  346.                     result3 = Math.floor((Math.random()*5)+1);
  347.                     result4 = Math.floor((Math.random()*5)+1);
  348.                     result5 = Math.floor((Math.random()*5)+1);
  349.                     result6 = Math.floor((Math.random()*5)+1);
  350.  
  351.                     break;
  352.                 case "6":
  353.                     result1 = Math.floor((Math.random()*6)+1);
  354.                     result2 = Math.floor((Math.random()*6)+1);
  355.                     result3 = Math.floor((Math.random()*6)+1);
  356.                     result4 = Math.floor((Math.random()*6)+1);
  357.                     result5 = Math.floor((Math.random()*6)+1);
  358.                     result6 = Math.floor((Math.random()*6)+1);
  359.  
  360.                     break;
  361.                 case "8":
  362.                     result1 = Math.floor((Math.random()*8)+1);
  363.                     result2 = Math.floor((Math.random()*8)+1);
  364.                     result3 = Math.floor((Math.random()*8)+1);
  365.                     result4 = Math.floor((Math.random()*8)+1);
  366.                     result5 = Math.floor((Math.random()*8)+1);
  367.                     result6 = Math.floor((Math.random()*8)+1);
  368.  
  369.                     break;
  370.                 case "10":
  371.                     result1 = Math.floor((Math.random()*10)+1);
  372.                     result2 = Math.floor((Math.random()*10)+1);
  373.                     result3 = Math.floor((Math.random()*10)+1);
  374.                     result4 = Math.floor((Math.random()*10)+1);
  375.                     result5 = Math.floor((Math.random()*10)+1);
  376.                     result6 = Math.floor((Math.random()*10)+1);
  377.  
  378.                     break;
  379.                 case "12":
  380.                     result1 = Math.floor((Math.random()*12)+1);
  381.                     result2 = Math.floor((Math.random()*12)+1);
  382.                     result3 = Math.floor((Math.random()*12)+1);
  383.                     result4 = Math.floor((Math.random()*12)+1);
  384.                     result5 = Math.floor((Math.random()*12)+1);
  385.                     result6 = Math.floor((Math.random()*12)+1);
  386.  
  387.                     break;
  388.                 case "20":
  389.                     result1 = Math.floor((Math.random()*20)+1);
  390.                     result2 = Math.floor((Math.random()*20)+1);
  391.                     result3 = Math.floor((Math.random()*20)+1);
  392.                     result4 = Math.floor((Math.random()*20)+1);
  393.                     result5 = Math.floor((Math.random()*20)+1);
  394.                     result6 = Math.floor((Math.random()*20)+1);
  395.                     break;
  396.                     }
  397.             }
  398.                   switch (input1) {
  399.                       case "1":
  400.                           JOptionPane.showMessageDialog(null,"You rolled a "+ result1);
  401.                           break;
  402.                       case "2":
  403.                           sum = result1 + result2;
  404.                           JOptionPane.showMessageDialog(null,"You rolled a " + result1 + "\n and a " +result2+"\n\n Total: "+sum);
  405.                           break;
  406.                       case "3":
  407.                           sum = result1 + result2 + result3;
  408.                           JOptionPane.showMessageDialog(null,"You rolled a " + result1 + "\n and a " +result2+ "\n and a " +result3+"\n\n Total: "+sum);
  409.                           break;
  410.                       case "4":
  411.                           sum = result1 + result2 + result3 + result4;
  412.                           JOptionPane.showMessageDialog(null,"You rolled a " + result1 + "\n and a " +result2+ "\n and a " +result3+ "\n and a " +result4+"\n\n Total: "+sum);
  413.                           break;
  414.                       case "5":
  415.                           sum = result1 + result2 + result3 + result4 + result5;
  416.                           JOptionPane.showMessageDialog(null,"You rolled a " + result1 + "\n and a " +result2+ "\n and a " +result3+ "\n and a " +result4+ "\n and a " +result5+"\n\n Total: "+sum);
  417.                           break;
  418.                       case "6":
  419.                           sum = result1 + result2 + result3 + result4 + result5 + result6;
  420.                           JOptionPane.showMessageDialog(null,"You rolled a " + result1 + "\n and a " +result2+ "\n and a " +result3+ "\n and a " +result4+ "\n and a " +result5+ "\n and a " +result6+"\n\n Total: "+sum);
  421.                           break;
  422.                   }
  423.         }
  424.     }
  425. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement