banner



Design A Dice Game With Java

posted 1 year ago

  • Mark post as helpful
  • send pies

    Number of slices to send:

    Optional 'thank-you' note:

  • Quote
  • Report post to moderator

This is a copy of the UML you showed us. Remember you

must

follow the UML to get full marks, even if I think the UML isn't ideal.Did you copy the class name correctly? I would expect it to be

D

ie.
I worry when I see

setXXX()

methods for everything. Yes, I know the books tell you to write them, but I don't think they are usually good OO design. You are able to change the player's name on that Die. Yes, it can happen that player 1 starts a game and player 2 finishes it. 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.

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.
Moderate quibble: You are shown two constructors which might neither of them get an object into a consistent state. If you call

new Die(6)

you will probably get a die without user names; if you call

new Die("XYZ‑12345", "Olu")

you might not necessarily set the sides. It is however easy enough to write code in that constructor to initialise sides. Please compare the constructors you were told to use with what you have written.

This where I start seeing problems. You have been given an overspecified assignment, which means you don't get marked for your ability to write object code, but your ability to follow a UML diagram. I think you are thereby forced into less than perfect design. I don't think a die "knows" who is rolling it. I think it would be better design to have a Player class, which will have the name. I think a player HAS A die and a die DOESN'T HAVE a player. Also, dice don't remember past scores. The players or the game would have to remember those scores. Similarly the game will determine a winner, not a die.

Design A Dice Game With Java

Source: https://coderanch.com/t/730879/java/Dice-Game-java

Posted by: pachecoambee1997.blogspot.com

0 Response to "Design A Dice Game With Java"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel