Residency & state taxes

I am working on taxes for my son.  We live in California.  He went to school in NY for his undergraduate work, worked for the summer, and returned back to the same school in NY for his graduate work.  So, he was effectively a student for the year, and a summer internship.

 

During his summer internship, the company put him up in NYC, but the office was in NJ.

 

He received a W-2 which included:
- The address on the W-2 is the NYC address where the company put him up.

- State taxes in CA, NJ, and NY. 

- The sum of the CA and NJ state wages (Box 16)  is the total in Box 1, with state taxes in Box 17 

- The NY state wages is the same as the total in Box 1, with a small amount deducted in Box 17

So, I have a few questions:
(1) What state is he considered a resident of?  CA since this is home address?  And if so, is he considered a non-resident of NJ and a part-time resident of NY?  Or is he considered a resident of  NY?
(2) What order should do the calculations based on (1)
(3) How do I handle double-taxing in these 3 states?

Any guidance would be appreciated!