✔ 最佳答案
The two can be used interchangeably.
If I were to make a distinction based on a fine shade of meaning, it would be that mandatory suggests something that you must do. Compulsory suggests something that you will be made to do. Ultimately, if you must do something, it is because you must do it, but compulsory focuses slightly more on the fact that you will be compelled (forced) to do it. If your friend or boss tells you that you must do it, it is mandatory. If police with guns will put you in jail if you don't do it, it is compulsory.
Your usages are incorrect, though.
Buying this textbook is mandatory for all students.
Students are mandated to attend the sports carnival. (Less common)
Attending the sports carnival is mandatory (more common)
It is not mandatory for you to come to the party.
Attendance at the party is not mandatory.
Attendance at the party is not compulsory.