Since what I posted was a bit hard to follow I'll post it again. I am using an IDE, Eclipse (Mars) by the way. It's just that like I said that my laptop was open and on while I typed away at the forum via another pc. My wifi in the house dosen't work so I coudn't use my laptop to post on the forum.
This is the main class.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner ChoiceONE = new Scanner(System.in);
Scanner ChoiceSixSides = new Scanner(System.in);
Scanner howMany = new Scanner(System.in);
int indicator = 0;
System.out.println("Welcome to Dice Roller. Which dice would you like to throw?");
int whichOptionInMenu = ChoiceONE.nextInt();
do {
if (whichOptionInMenu == 1){
//how can I make this throw more than one dice at a time?
System.out.println ("How many 6 sided dice do you want to roll?");
int throwerOne = howMany.nextInt();
DiceRoller mydice = new DiceRoller(throwerOne);
//while (throwerOne == indicator){
System.out.print(mydice.DiceRoller()+ " is what the dice rolled.\n");
//}
}
if (whichOptionInMenu == 2){
DiceRoller mydice = new DiceRoller(whichOptionInMenu);
mydice.DiceRollerTWO(whichOptionInMenu);//Find another way to call the needed method WITHOUT using an Int.
}
System.out.println("");
System.out.println("Welcome back to Dice Roller. Which dice would you like to throw now? ");
System.out.println("");
System.out.println("Click Option 1: For D6 or six sided dice." +
"Click Option 2: For D10 or 10 sided dice" + " Click Option 3: To quit the program.");
whichOptionInMenu = ChoiceONE.nextInt();
} while (whichOptionInMenu != 3);
ChoiceONE.close();
ChoiceONE.close();
}
}
And here is my diceroller.
import java.util.Random;
import java.util.Scanner;
public class DiceRoller {
public DiceRoller(int x){
Random d6Generator = new Random();
Scanner howMany = new Scanner(System.in);
System.out.println ("How many 6 sided dice do you want to roll?");
int throwerOne = howMany.nextInt();
int sixSidedDice = d6Generator.nextInt(6) + 1; // What does this mean in Synthax?
}
public int DiceRollerTWO(int x){
Random D10Generator = new Random();
int tenSidedDice = D10Generator.nextInt(10) + 1; // Being called but the dice syntahx is incorrect.
System.out.println("You got: " + tenSidedDice);
return tenSidedDice;
}
}
Working on fixing a few things still for the OOP version. Thanks @Reelya for the help.
Also you may notice that this code dosen't run and that's because I fiddled with it after it was working to try and get multiple dice to work on it. As I have said before, no dice. Pun intended
EDIT:
Having a hard time visualizing what I need to do. This is a guess but..
1. Public Class Dice.
2. Make traits for Class Dice. Such as int sides.
3. Make a function that 'gets' sides. You know like getSides.
4. Another function transfer whatever getSides is (It will be int something) and put it in a roll function.
- random
- random(getSides) + 1;
This seems like a good track from guess work. Btw I was looking at Reelya's suggestion and formulating as I type. This still leaves me with two questions though: 1. How to make multiple rolls and 2. the actual coding.
I know I can't be helped with the last one, that's what my 80$ book is for, but how can I get it to roll more than once? Can I make another function that does that seprately?
something like...
class DiceXXXXX
while (userwanted to roll){
random(getSides)+ 1;
}
Not sure if that'll work since I tried it before...Either still working on all of this.