Well we know he has 12 more coins nickles than his quarters, so (12+q) represents that he has 12 more than his quarters. Now what the "5" represents is the value of the nickle (in cents).How did he get the 5(q+12). How did he even know how to set the formula like that?

What goes where?

25q : 25 represents the value of a quarter in cents, and q is the amount he has.

So, the question tells us that when he has both amount of quarters and nickles he has 270 cents

So,

25q + 5(q+12) = 270

25q + 5q + 60 =270

30q = 210

q= 210/30

q= 7

There fore he has 7 quarters and (q+12) -> (7+12) = 19 nickles.

To check, is this true : 25(7) + 5(19) = 270?

Yes, then our solution is right.