![]() You've hardcoded the dices and this is bad for you and the user of your class. If you have no comment for a parameter or other stuff, remove the Redundancy isn't nice. Otherwise, they will complain about it, even if it were their mistake. In a project with more than one guy, you should prevent the others as much as reasonable from doing bad stuff with your code. In this case, your class is not final and I could extend it, but did you design your class to be extended? Probably not and thus you should make it final. I guess you're working here on your own, but I would suggest getting used to the practice of making everything final if possible. I know what a Dice is and I know people that can use the dice to roll it, but calling them "DiceRoller" would be strange and I cannot imagine what a DiceRoller would be otherwise, so I would suggest renaming the class in a way that isn't that much concerned about the behaviour of the class. ![]() Return (max - min + 1) + min įor(int i = 0 i = 1 & roll = NUM_DICE & roll = 1 & roll = NUM_DICE & roll = 1 & roll = NUM_DICE & roll = 1 & roll = NUM_DICE & roll = 1 & roll = NUM_DICE & roll = 1 & roll = NUM_DICE & roll = 1 & roll = NUM_DICE & roll = 1 & roll = NUM_DICE & roll = 1 & roll = NUM_DICE & roll <= (NUM_SIDES * NUM_DICE)) * Helper function to generate numbers between min and max inclusive * Helper function to generate numbers between 1 and max inclusive * the result of rolling n hundred-sided dice * the result of rolling a hundred-sided die * the result of rolling n twenty-sided dice * the result of rolling a twenty-sided die * the result of rolling n twelve-sided dice * the result of rolling a twelve-sided die * the result of rolling n eight-sided dice * the result of rolling a eight-sided die ![]() * the result of rolling n four-sided dice This.rnd = new Random((long) Math.random()) I finished my first class, DiceRoller and am looking for input and advice. I'm focusing on best practices, especially testing and documentation as I'd like to start contributing to Open Source projects. I am coding in with IntelliJ using Java 8. Here's a quick rundown of what you need to know (but know the approaches above for future problems):įile: Dice.In order to keep my coding skills fresh, I am going to be implementing a simple D20 RPG engine/library to use in creating a text-based game. You can research these things by Googling something like "java introduction tutorial create class" or similar for each of these. You will also need to know how to define a class of your own, called Dice with an instance variable numberShowing and instance methods roll and main. It describes how the class you've been told to use works. Try Googling "java understanding api documentation" or similar. Your first job is to work out how to read this and understand it. It's hard when things are new and don't be discouraged if you don't know where to start. Please help me get this code written.įirst, don't panic. I can't tell you how high my anxiety level is right now, nor how much I despise this. I have started at this computer for hours, and read as much info as I can. Can you keep track of how many times a number comes up? Describe how or implement it in the program." The last part reads "Create a test main method for the Dice class that creates a dice and rolls it many times. It has to use, not math.java, and it has to have numberShowing:int, roll():int, and main() all in it. It should have a method called roll() that randomly selects a number from 1-6 for the value of the dice." Mine says: "Create a class called Dice to represent a SINGLE cube". I've also been pouring over examples on here and elsewhere online, but none of them exactly match what I'm doing, as they all say "Pair of Dice". I've done it twice already, but clearly I still have no idea what I'm doing. I have absolutely no Java experience, and I need to work on this "Dice" program. I posted about this yesterday, but I think I need to make it less involved.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |