I will work part a for you; you work part b in a similar manner.
If you put a calf in either end stall there 5 other stalls in which to put the other calf: 2 calves, 2 ends, 5 choices and then there are 5! arrangements of the cows.
If you put a calf in a stall of than an end there are 4 other stalls in which to put the other calf: 2 calves, 4 choices and then 5! arrangements for cows.
That means 20* 5! + 8*5! = 28*5!