public Money [ ] share ( int numberOfShares ) { if ( numberOfShares <= 0 ) { throw new IllegalArgumentException ( "Number of shares has to be greater than zero." ) ; } int ratios [ ] = new int [ numberOfShares ] ; Arrays . fill ( ratios , 1 ) ; long [ ] amountAllocation = MoneyMath . allocate ( amount , ratios ) ; Money allocation [ ] = new Money [ ratios . length ] ; for ( int i = 0 ; i < ratios . length ; i ++ ) { allocation [ i ] = new Money ( currency , fraction , amountAllocation [ i ] ) ; } return allocation ; }
The method calculates equal shares . Only the number of shares need to be specified .