Last active
December 19, 2015 05:49
-
-
Save Xyphis12/5907262 to your computer and use it in GitHub Desktop.
com.dtalley11.dice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dtalley11.dice; | |
import java.util.*; | |
public class Dice { | |
public int[] Diceroll(int size, int num) { | |
int[] rolls = new int[num+1]; | |
for(int loopa = num; loopa > 0; loopa = loopa-1) | |
Random generator = new Random(); | |
int finroll = generator.nextInt(size) + 1; | |
rolls[num+1] = finroll | |
} | |
int sum = 0; | |
for (int i : rolls) { | |
sum += i; | |
} | |
rolls[num+1] = sum; | |
return (rolls); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dtalley11.dice; | |
import java.util.*; | |
public class Dicedriver { | |
public static void main(String[] args) { | |
if (args[0] == "help") { | |
errormsg(); | |
} | |
try { | |
int num = Integer.parseInt(args[0]); | |
int size = Integer.parseInt(args[1]); | |
} | |
catch (NumberFormatException|ArrayIndexOutOfBoundsException e) | |
errormsg(); | |
} | |
System.out.println("Rolling "+ num + "d" + size); | |
Dice die = new Dice(); // Create an Instance | |
if (num == 1) { | |
System.out.println("Your Rolled a " + die.get(0)); | |
} | |
else { | |
System.out.print("Your Rolled a " + die.get(0) + " "); | |
die.remove(0); | |
System.out.print(die); | |
} | |
} | |
public static void errormsg() { | |
System.out.println("\r\nDice Roll Needs 2 Arguments"); | |
System.out.println("\r\njava dice x y'"); | |
System.out.println("\r\nWhere x is the amount of dice you wish to roll, and y is the amount of sides on the die/dice"); | |
System.exit(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment