Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>mukhtar.alfatih</groupId>
<artifactId>ReusingClasses</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>

</dependencies>


</project>
7 changes: 7 additions & 0 deletions src/main/java/ReusingClasses/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ReusingClasses;

/**
* Created by alfatihmukhtar on 1/18/17.
*/
public class App {
}
39 changes: 39 additions & 0 deletions src/main/java/ReusingClasses/ArrayRotationHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ReusingClasses;

import java.util.Arrays;

/**
* Created by alfatihmukhtar on 1/18/17.
*/
public class ArrayRotationHandler {
// take in factor "x" to rotate by
// rotate every item in array by "x" places

// create method that takes two arguments (array, k) where k = number of elements to rotate.
public int[] rotateArray(int[] array, int rotation) {
// System.out.print("The initial array is: ");
// for(int i=0; i<array.length; i++) {
// System.out.println(array[i]);
// }
System.out.println(Arrays.toString(array));
int[] valuesLessThanRotationAmount = new int[array.length];
for(int j=0; j<rotation; j++) {
valuesLessThanRotationAmount[j] = array[j];

}
for(int k=rotation;k<array.length;k++) {
array[k-rotation] = array[k];
}
for(int h=0;h<rotation;h++) {
array[array.length-(rotation-h)] = valuesLessThanRotationAmount[h];
}
// System.out.print("The new array is: ");
// for(int i=0; i<array.length; i++) {
// System.out.println(array[i]);
// }
System.out.println(Arrays.toString(array));

return new int[0];
}

}
9 changes: 9 additions & 0 deletions src/main/java/ReusingClasses/List.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ReusingClasses;

/**
* Created by alfatihmukhtar on 1/18/17.
*/
public class List {
int[] list = {1,2,3,4,5,6,};

}
26 changes: 26 additions & 0 deletions src/test/java/ResusingClassesSpec/ArrayRotationHandlerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ResusingClassesSpec;

import ReusingClasses.ArrayRotationHandler;
import org.junit.Test;

import java.util.Arrays;

import static org.junit.Assert.assertTrue;

/**
* Created by alfatihmukhtar on 1/18/17.
*/
public class ArrayRotationHandlerTest {
@Test
public void rotateArrayTest() {
ArrayRotationHandler test = new ArrayRotationHandler();
int[] expected = {3,4,5,6,1,2};
int[] inputArray = {1,2,3,4,5,6};
int[] actual = test.rotateArray(inputArray, 2);
System.out.println(expected);


assertTrue(Arrays.equals(expected, actual));

}
}