Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="module-library"> | ||
<library> | ||
<CLASSES> | ||
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" /> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" /> | ||
</CLASSES> | ||
<JAVADOC /> | ||
<SOURCES /> | ||
</library> | ||
</orderEntry> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
public class NthPlaceLoser { | ||
|
||
|
||
public static Student NthPlaceLoser(Student[] aList, int N) { | ||
// TODO implement this yourself | ||
return aList[0]; | ||
} | ||
|
||
/*************************************************************************** | ||
* Helper sorting functions. | ||
***************************************************************************/ | ||
|
||
/** | ||
* This method returns whether a student is less than another student in respect | ||
* to how your compareTo method is defined | ||
* @param v First Student | ||
* @param w Second Student | ||
* @return if v (first student) is less than w (second student) | ||
*/ | ||
private static boolean less(Student v, Student w) { | ||
if (v == w) return false; // optimization when reference equals | ||
return v.compareTo(w) < 0; | ||
} | ||
|
||
/** | ||
* This method exchanges a[i] and a[j] in an array | ||
* @param a array in which you want to swap | ||
* @param i index of first item | ||
* @param j index of second item | ||
*/ | ||
private static void exch(Object[] a, int i, int j) { | ||
Object swap = a[i]; | ||
a[i] = a[j]; | ||
a[j] = swap; | ||
} | ||
|
||
/*************************************************************************** | ||
* Main method | ||
***************************************************************************/ | ||
|
||
public static void main(String[] args) { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import org.junit.Test; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class NthPlaceLoserTest { | ||
|
||
@Test | ||
public void exampleTest() { | ||
Student[] students = new Student[10]; | ||
for (int i = 0; i < 10; i++) { | ||
students[i] = new Student(i+1 ,Integer.toString(i)); | ||
} | ||
|
||
assertEquals(NthPlaceLoser.NthPlaceLoser(students, 1 ).rank, 9); | ||
assertEquals(NthPlaceLoser.NthPlaceLoser(students, 3 ).rank, 7); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public class Student implements Comparable<Student>{ | ||
public int rank; | ||
public String name; | ||
|
||
public Student(int rank, String name){ | ||
this.rank = rank; | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public int compareTo(Student o) { | ||
// TODO implement this yourself | ||
return 0; | ||
} | ||
|
||
} |