I would say that the solution would depends mainly on your use case and the performance you are aiming for.
The more simplistic approach I could think of is the following in pseudo code:
declare an array to hold the circles to draw on canvas
While the number of circle in the array is less than 20:
chose a random (x, y) coordinates where you will draw your next circle
for all circles in the array:
Check if the distance between its center and the center of the new circle is larger than the sum of their radius
if it is not the case:
move to the next loop
Add the new circle to the array. Since you arrive at this line, it means that you did not move to the next loop which means that the distance between the new circle and each of the other circles is larger than the sum of their radius which means that it is not overlapping either of them.
I mean any teacher worth their salt will ask them to explain the logic or why they chose to complete the project the way they did, and in that case the teacher would find out the student doesnt know how he achieved the result.
If they can figure out the code and the logic and explain it, then its fine though. Plus this is coded in p5.js, the question was in processing java, so they still have to complete the conversion.
I was waiting for my son to come out of school and the question popped into my head…. I thought I would ask and was very pleasantly surprised with the responses. Seems like a nice, helpful community… hopefully I can pay the kindness back myself one day.