+2 votes

You have two choices. You can either store the percentages in the array rounded to tenths in the getPercentages method OR display them to tenths in the reportResults method.

To store the value rounded to tenths, use this kind of arithmetic. Say your computation gave you a percentage of 24.38214. Then Math.round(24.38214 * 10) / 10.0 = 24.4....That's because multiplying by 10 given 243.8214. Math.round(243.8214) is 244. Finally 244/10.0 = 24.4. Voila, it's rounded to tenths. If the values are stored rounded to tenths, then in reportResults, you can use Arrays.toString to print out the array easily.

Alternatively, you can store the numbers in the array unrounded. In that case reportResults will need to use a loop to print out the array element by element using printf or df.format to round each element one by one and also provide the square brackets and the commas.