java - How to make a Loaded Dice -



java - How to make a Loaded Dice -

i creating subclass of dice class called loaded dice create dice roll loaded , percent, bit like;

public loadeddice (int anumsides,int loadval, double loadpct)

but don't know start, i've gotten ideas create arraylist , create have more of 1 number others , pick randomly there there's got cleaner way right?

public class dice { // -------------------------------------------- // instance variables // -------------------------------------------- private arraylist<die> diearray; // ------------------------------------------------ // constructors // ----------------------------------------------- /** * default constructor creates 2 6 sided dice */ public dice () { diearray = new arraylist<die>(); diearray.add(new die()); diearray.add(new die()); } /** * takes arraylist of die objects utilize */ public dice (arraylist<die> somedice) { diearray.addall(somedice); } /** * takes in 1 int (# of dice), creates number of 6-sided * dice */ public dice (int numberofdice) { diearray = new arraylist<die>(); (int = 0; < numberofdice; i++) { diearray.add(new die()); } } /** * takes in 2 ints (# of dice, # of sides per die) creates * number of dice number of sides per die */ public dice (int numberofdice, int numberofsides) { diearray = new arraylist<die>(); (int = 0; < numberofdice; i++) { diearray.add(new die(numberofsides)); } } // ------------------------------------------------- // class methods // ------------------------------------------------- /** * containsdice: takes 0 parameters, , returns string value * representing of dice */ public string containsdice () { string diestring = new string(); (int = 0; < diearray.size(); i++) { diestring += (diearray.get(i) + " "); } homecoming diestring; } /** * roll: takes 0 parameters, , returns int value sum * of dice rolled */ public int roll () { int value = 0; (int = 0; < diearray.size(); i++) { value = value + diearray.get(i).roll(); } homecoming value; } /** * add: takes die object input parameter , adds * current dice */ public void add together (die newdie) { diearray.add(newdie); } }

also of dice class coming die class created. if needed can provide well.

java

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -