Skip to content

Commit

Permalink
Skeleton code for NthPlaceLoser
Browse files Browse the repository at this point in the history
  • Loading branch information
awhicks committed Jan 30, 2019
1 parent 84a1b88 commit 0489204
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions NthPlaceLoser/NthPlaceLoser.iml
@@ -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>
45 changes: 45 additions & 0 deletions NthPlaceLoser/src/NthPlaceLoser.java
@@ -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) {

}

}
18 changes: 18 additions & 0 deletions NthPlaceLoser/src/NthPlaceLoserTest.java
@@ -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);

}

}
16 changes: 16 additions & 0 deletions NthPlaceLoser/src/Student.java
@@ -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;
}

}

0 comments on commit 0489204

Please sign in to comment.