Minor quibble: You have constructors in that UML and they are called “method mmbers”, but constructors are neither methods nor members of a Java® class. But would you want to change the number of sides? If it says so in the UML, however, you will have to implement those methods. Yes, it can happen that player 1 starts a game and player 2 finishes it. You are able to change the player's name on that Die. Yes, I know the books tell you to write them, but I don't think they are usually good OO design. I worry when I see setXXX() methods for everything. class: dieĭid you copy the class name correctly? I would expect it to be Die. Remember you must follow the UML to get full marks, even if I think the UML isn't ideal. All the other fields you have in the current Die class should be removed, along with the methods associated with them.Īt this point I am going to disagree with the UML and tell you to query it with your teacher, but this will be the subject of a future post. You are going to have to give it more fields, however, because that is what the UML says. I can understand that a Die would have a field which the UML calls value, and that is the current face showing, but I wouldn't give it any more fields. You have called it MAX, which would be acceptable, but if you spell it MAX rather than max, make that field final. You have all sorts of fields which aren't in the UML. Please go back to the UML diagram Unfortunately you haven't made the die match that UML diagram. Good to see somebody who knows how to format code well I hope I have made the code and the UML look better by wrapping them with the code button, as JJ suggested. Private int MAX = 6 // maximum face value Private Random myRandGen // the random number generator Private int myRollCount // # times rolled Private int die2 // Number showing on the second die. Private int die1 // Number showing on the first die. " a 6 sided die\nRolling the Dice 10 Times") ("This Simulates the rolling of 6 sided die and" There is tie between computer xyz-1234 and user HanĬan Someone help me on this code and check if everything is correct This simulates the rolling of a 6 sided die and a 6 sided die All computer name follow this pattern, otherwise they are invalid. Computername is a specially-formed String that consists of 3 letters (can be upper-case or lower-case), followed by a dash, followed by 4 numbers. After the loop performs all of its iterations, the program should display who was the grand winner, the computer or the user. (In case of a tie, there is no winner for that particular roll of the dice.) As the loop iterates, the program should keep count of the number of times the computer wins, and the number of times that the user wins. Generate another random integer in the range of 1 through 6. Each iteration of the loop should do the following: Generate a random integer in the range of 1 through 6. When the program runs, a loop should repeat 10 times. Dice Game Write a program that plays a simple dice game between the computer and the user.
0 Comments
Leave a Reply. |