# 0.2. Quiz

## Coding

Right-click on the [`src/main/java`](https://github.com/emory-courses/dsa-java/tree/master/src/main/java) directory under the project and create the package [`edu.emory.cs.utils`](https://github.com/emory-courses/dsa-java/tree/master/src/main/java/edu/emory/cs/utils). Right-click on the `utils` package and create the Java class [`Utils`](https://github.com/emory-courses/dsa-java/blob/master/src/main/java/edu/emory/cs/utils/Utils.java):

* Add `Utils.java` to git.
* Add the following methods to the `Utils` class:

```java
static public int getMiddleIndex(int beginIndex, int endIndex) {
    return beginIndex + (endIndex - beginIndex) / 2;
}

static public void main(String[] args) {
    System.out.println(getMiddleIndex(0, 10));
}
```

Run the program by clicking `[Run -> Run]`.  If you see `5` on the output pane, your program runs successfully.

## Testing

Open [`build.gradle`](https://github.com/emory-courses/dsa-java/blob/master/build.gradle) and add the following configurations (if not already), which would allow you to perform [JUnit Testing](https://junit.org/junit5/):

```groovy
test {
    useJUnitPlatform()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}
```

Right-click on the [`src/test/java`](https://github.com/emory-courses/dsa-java/tree/master/src/test/java) directory under the project and create the package [`edu.emory.cs.utils`](https://github.com/emory-courses/dsa-java/tree/master/src/test/java/edu/emory/cs/utils).  Right-click on the `utils` package and create the Java class [`UtilsTest`](https://github.com/emory-courses/dsa-java/blob/master/src/test/java/edu/emory/cs/utils/UtilsTest.java):

* Add `UtilsTest.java` to Git.
* Add the following method to the `UtilsTest` class.  Make sure to include all imports:

```java
package edu.emory.cs.utils;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

@Test
public void getMiddleIndexTest() {
    assertEquals(5, Utils.getMiddleIndex(0, 10));
}
```

Run the test by clicking `[Run -> Run]`.  If you see the test passed, your unit test runs successfully.

## Submission

1. Add the instructors as collaborators in your GitHub repository:

* Jinho Choi: `jdchoi77`
* Peilin Wu: `qualidea1217`
* Jeongrok Yu: jeongrok
* Zinc Zhao: `ZincZhao`

2\. Commit and push the following to your GitHub repository:

* [gradle/wrapper/gradle-wrapper.jar](https://github.com/emory-courses/dsa-java/blob/master/gradle/wrapper/gradle-wrapper.jar)
* [gradle/wrapper/gradle-wrapper.properties](https://github.com/emory-courses/dsa-java/blob/master/gradle/wrapper/gradle-wrapper.properties)
* [.gitignore](https://github.com/emory-courses/dsa-java/blob/master/.gitignore)
* [build.gradle](https://github.com/emory-courses/dsa-java/blob/master/build.gradle)
* [gradlew](https://github.com/emory-courses/dsa-java/blob/master/gradlew)
* [gradlew.bat](https://github.com/emory-courses/dsa-java/blob/master/gradlew.bat)
* [settings.gradle](https://github.com/emory-courses/dsa-java/blob/master/settings.gradle)
* [src/main/java/edu/emory/cs/utils/Utils.java](https://github.com/emory-courses/dsa-java/blob/master/src/main/java/edu/emory/cs/utils/Utils.java)
* [src/test/java/edu/emory/cs/utils/UtilsTest.java](https://github.com/emory-courses/dsa-java/blob/master/src/test/java/edu/emory/cs/utils/UtilsTest.java)

3\. Submit the URL of your GitHub repository to Canvas.


---

# 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://emory.gitbook.io/dsa-java/getting-started/exercises.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.
