That's a good example! :) Students do go crazy, I know...
It's rather simple though.
Group notes first of all to one beat. But, sometimes you have to group them on two beats, like in measure one in your example:
1. A dotted quarter note plus two 16th notes make 2 beats: Beam the two 16th notes after the dotted quarter note together.
2. Then, you have two 16th notes and an 8th. Group them by beaming them. This is one beat.
3. Lastly, a dotted 8th note and a 16th note is one beat. Group them by beaming them together.
Continue in the same way to group the notes to one, or two beats max as long as it's a meter in 4/4.
Now, here's a little "secret":
A meter in 4 can be subdivided into 4 beats as you know now, by grouping the note values together in groups of 1 beat, and sometimes 2 beats.
BUT not 3+1 beats or 1+3 beats. I tell my students to imagine an invisible barline in the middle of the measure. Group the notes on each side to a maximum of 2 beats (for meter in 4), but never over this "invisible" line.
Download your FREE Piano Practice and Technique eBook, and stay up-to-date with my monthly newsletter "The Piano Player", with playing tips & tricks to keep you practicing!