To elaborate on qwerty_so's answer:
The UML constraint could be expressed, just next to the operation in the class:
in plain-text, like: { n between 1 and 6 }
using OCL syntax, like: { n>0 and n<=6 }
If it is a longer expression, you can also put it in a note symbol that is attached to the operation (in UML we say "operation" rather than "method").
More complex constraints could also be expressed in plain OCL, indicating a context
to which it applies (e.g. a specific class, property or operation). The constraint can express invariants (inv:
), and in the case of operations, also preconditions (pre:
) and post-conditions (post:
). In your case, it would look like :
context: MyClass::grade(n : Integer)
pre: n>0 and n<=6 -- expression could involve properties using prefix 'self.'
This could be expressed in an UML note attached to the class. But since it can be really complex, especially if you want to document the contract for each operation, it could also be held separately (e.g. in a constraint specification windows of your modelling tool, or as a text in complement to a diagram or a model).