0.2. Quiz

Quiz 0: Getting Started

Coding

Right-click on the src/main/java directory under the project and create the package edu.emory.cs.utils. Right-click on the utils package and create the Java class Utils:

  • Add Utils.java to git.

  • Add the following methods to the Utils class:

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 and add the following configurations (if not already), which would allow you to perform JUnit Testing:

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 directory under the project and create the package edu.emory.cs.utils. Right-click on the utils package and create the Java class UtilsTest:

  • Add UtilsTest.java to Git.

  • Add the following method to the UtilsTest class. Make sure to include all imports:

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:

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

Last updated

©2023 Emory University - All rights reserved