In the statement "The class has eight students," has is used because the subject class is considered 3rd person singular.
He, she, it (the class) has
In the question "Does the university have three libraries?" the rules are a little different. Even though "the university" is also 3rd person singular, that is reflected in the use of "does" (the auxiliary verb). The main verb (have) then does not change.
Do I have ...?
Do you have ...?
Does he, she, it (the university) have ...?
Do we have ...?
Do they have ...?