I'm a little confused and cannot find out how to write this in code from the UML diagram. I know it's a public class, and its first word is the method. I'm confused about the object array inside the method if it even is inside the method. Thanks for your time.
getSize(Scanner sc) : Object[]
friendOrFamily(Scanner sc) : int
CodePudding user response:
There is no array notation in UML. But the closest thing in UML is multiplicity combined with a type name (e.g. Object
) :
myarray: Object [*]
myboundedarray: Object[2..5]
myoptional: Object [0..1]
This means an unlimited number of objects, a bounded list of objects between 2 and 5 elements, and an optional object that can be absent (minimum 0) or present (maximum 1).
For operations (aka methods), you just indicate it with a column, after the parameter list:
getSize(sc: Scanner) : Object[*]
which describes an operation taking one parameter of type Scanner
and returning a container with an undertermined number of elements of type Object
.