The cost of Beta in each case is $0.75. Beta costs $1.50 per gram. Therefore each cake must be using 0.75/1.50 = 0.5 grams. It is the same logic for the other two.
After producing 5,000 shakes and 9,800 cookies there are only 5,040 grams of Beta left.
Since cakes use 0.5 grams of beta each, that means they can make 5,040 / 0.5 = 10,080 cakes.