John was in charge of buying milk for a class of 32 students. Milk is sold in half-gallon cartons and gallon cartons at the market. The half gallon costs 1.46 and the gallon costs 2.39. John bought all 21 cartons of milk the store had and paid 41.82. How many cartons of each size did he buy?

To determine the number of half-gallon cartons and gallon cartons John bought, we can set up a system of equations based on the given information.

Let's assume the number of half-gallon cartons is represented by 'x', and the number of gallon cartons is represented by 'y'.

From the given information, we can establish the following equations:

1) The total number of cartons: x + y = 21

2) The total cost: (cost of half-gallon cartons * number of half-gallon cartons) + (cost of gallon cartons * number of gallon cartons) = 41.82

Now, let's substitute the given values into the equations:

1) x + y = 21

2) (1.46 * x) + (2.39 * y) = 41.82

We have two equations with two variables. We can solve this system of equations to find the values of 'x' and 'y'.

Using the first equation, we can isolate 'x':

x = 21 - y

Substituting this value of 'x' into the second equation:

(1.46 * (21 - y)) + (2.39 * y) = 41.82

Simplifying the equation:

30.66 - 1.46y + 2.39y = 41.82

Combining like terms:

0.93y = 11.16

Dividing both sides by 0.93:

y = 12

Now, we can substitute this value of 'y' into the equation x = 21 - y:

x = 21 - 12

x = 9

Therefore, John bought 9 half-gallon cartons and 12 gallon cartons of milk.