∃x (D(x)^M(x))→∀y(F(y,x)^D(y))→q(y)
You have to pay attention to the "scope" of the quantifiers. How to define "scope" formally may be in the materials you are studying or it may only be treated informally. I can only explain it informally!
We already know that on a page in a math book, that a variable like 'x' may mean one thing in one paragraph and something different in the next. For example, in problem 1, 'x' may stand for one thing and in problem 23, 'x' may mean something different. This similar to the "scope" of variable in computer programming. The value of 'x' in the code for one function doesn't determine the value of 'x' in the code for another function, unless 'x' is variable whose "scope" includes both functions (such as a "global" variable).
When you use a quantifer "there exists" on the variable 'x' in an exression that contains lot's of x's, the "there exists" may only apply to a few of them. The way to be unambiguous about this is to use parentheses or brackets to show what a quantifier applies to.
For example:
"There is person in class who is smart and everyone in class is has limited abilities".
S(x): x is smart
L(x) : x has limited abilities
C(x): x is in class
\exists x \{ C(x) \wedge S(x) \} \wedge \forall x \{ C(x) \rightarrow L(x) \}
It is clearer to most human minds to write the above as:
\exists x \{ C(x) \wedge S(x) \} \wedge \forall y \{ C(y) \rightarrow L(y) \}
but it is not necesary to introduce the symbol 'y'. The symbol 'x' can be re-used by putting it in the scope of different quantifiers.
Someone reading your answer would have to interpret all the x's as being in the scope of the "there exists" and your answer, as I read it, claims: "There is a person with the property that if that person lives in the dormitory and has measels then all friends of that person who live in the dormitory must be quarantined."
You need to introduce another quantifier on the right hand side of the \rightarrow. The idea you need to express is that "for each y { if ( there is some x who lives in the dormitory and y is a friend of x) then (y must be quarantined)}.