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. There must be a single instance variable int faceValue, a void method roll with no parameters, a method getValue that simply returns the value of faceValue, and a method toString that returns a String representation of faceValue.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. Note: The methods' modifiers, return types, and parameters were defined in the assignment directions and must be exactly as specified. I have completed the program and it seems to work alright, but I was hoping to get some advice/suggestions on how to better optimize my code, as I feel it is a little messy. Should be, at minimum, a method that accepts an array of Die objectsĪs a parameter and rolls each Die object once and another method thatĪccepts the same array as a parameter and tests to see if a Yahtzee The use of helper methods isĮncouraged and most methods should be around 12 lines or less. These periods will be printed on the same line and a newline character Rolled, so as to indicate to the user that the program is working. The program should give the user the option to run itĪlso, it should print out a single period each time the dice are How many rolls it took to obtain the Yahtzee, and what face value made Is rolled occurs when all the dice have the same face value and report The program should then repeatedly roll all the dice until a Yahtzee Positive), and create an array of Die objects of the specified size. The user how many dice the he/she wants to roll (number must be The program should give an introduction of what it is going to do, ask An overview of the directions are as follows: As part of an assignment for my intro Java class (please bear with my beginner skill set), I'm working on a program for which a Die object class is used to play a Yahtzee game.
0 Comments
Leave a Reply. |