Let us say that:
V1 = initial gallons in first container
V2 = initial gallons in second container
From the problem statement, we can create the equations:
V1 = 2 V2
V1 – 3 = 4.5 (V2 – 2)
Combining the two:
2 V2 – 3 = 4.5 (V2 – 2)
2 V2 – 3 = 4.5 V2 – 9
2.5 V2 = 6
V2 = 2.4 gallons
V1 = 2 V2 = 4.8 gallons
So there are 4.8 gallons in the 1st container while 2.4 gallons in the 2nd container.