-
Notifications
You must be signed in to change notification settings - Fork 5
Getting Started
jdchoi77 edited this page Jan 4, 2015
·
8 revisions
- Download the latest version of JDK from here and install.
- Make sure the version is 1.8.x or higher by typing
java -version
on a terminal.
- Download the latest version of Eclipse from here and install.
- Launch Eclipse by double-clicking the icon.
- If it prompts to specify a working directory, keep the default one (
Workspace
). - If it shows a
Welcome
tab, close the tab. - Create a new project
CS323
by choosingFile -> New -> Java Project
. - Create a package
cs323.utils
by right-clicking[CS323] -> New -> Package
. - Create a class
MathUtils
by right-clicking{cs323.utils} -> New -> Class
. - Add the following methods to the
MathUtils
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 choosing
Run -> Run
. - If you see
5
on the console, your program is successfully run.
- Right click on the
CS323
project and chooseBuild Path -> Add Libraries
. - Choose
JUnit
and addJUnit 4
. - Create a class
MathUtilsTest
under theutils
package. - Add the following method to the
MathUtilsTest
class. - Make sure to include the
@Test
annotation.
@Test
public void testSum()
{
assertEquals(MathUtils.getMiddleIndex(0, 10), 5);
}
- Run the test by choosing
Run -> Run
. - If you see a green bar, all your tests have passed.
©2015 Emory University