If all the psychology books are together, then so are all the mathematics textbooks
The books can be arranged in two ways (psychology first and then math, or vice-versa)
And for each of these the math books can be arranged in 4! = 24 ways
And the psychology books can be arranged in 3! = 6 ways
So
6 * 24 * 6 = 864 arrangements