This is an example of direct speech. What the speaker says is presented in Japanese quotation marks「 」without changing the "です/ます" ending. The utterance is followed by と and a reporting verb(e.g., say, hear). Greetings and what animals "say" can also be put in quotation marks and reported by using と and the appropriate verb.
わたしは 先生に 「よく わかりました。」と 言いました。
I said to my teacher, "I understand clearly."
犬は 「ワン」と なきます。
Dogs bark, "Wan."
日本では あさ 「おはようございます。」と あいさつを します。
In Japan, people greet each other in the morning with "Ohayoo gozaimasu."