You can cut the words"上课" into two parts "上" and "课"
The first part is a verb means "have" or "go to have"
The second part is a noun means "lesson" or "class"
"吃饭" is same as "上课"
吃 is eat and 饭 is food or meal
So 完 just follow the verb to explain you have done this action already
It not follow the noun or before the verb