# Parse Student Code

Often you just want to make sure students successfully used a particular function/command/structure.  The simplest way I have found to do this is just parse the student's code file and make sure what you are looking for is there.

For example, maybe you want to make sure the student used `println()` at least 2 times.  We can parse the student's code file and count how many times `"System.out.println("` is present in their code.

This test assumes the student's file name is `Example.java`.

```java
import org.junit.Test;
import static org.junit.Assert.*;
import java.nio.file.*;

public class CodingRoomsUnitTests {

    @Test
    public void testDefaultCase() throws Exception {
        int count = 0;
        String student_code = new String(Files.readAllBytes(Paths.get("Example.java")));
        String[] words = student_code.split(" ");

        for (int i = 0; i < words.length; i++) {
            if (words[i].indexOf("System.out.println(") >= 0) {
                count++;
            }
        }
        assertTrue(count >= 2);
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://auto-grade.joemazzone.net/java/parse-student-code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
