Example:

A CD player and its battery together do 500 kJ of work. The battery releases 250 kJ of energy as heat and the CD player releases 50 kJ as heat due to friction from spinning. What is the change in internal energy of the system? The battery and CD player are considered the system.

Answer:

The CD player and battery are the system and they do work. Therefore, w = –500 kJ. 
Because both the battery and CD release heat, q = –(250 + 50) = –300 kJ. Therefore,

the change in internal energy = DU = q + w = –300 + (–500) = –800 kJ