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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>4.12</version>
</dependency>
</dependencies>

Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/dtcc/exams/part1/DelTechConcatenator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.dtcc.exams.part1;

public class DelTechConcatenator {

Integer value;

public DelTechConcatenator(){
this(null);
}
public DelTechConcatenator(Integer val){
this.value = val;
}

public boolean isDel(){
return (value % 3 ==0);
}

public boolean isTech(){
return (value % 5 ==0);
}

public boolean isDelTech(){
return (value % 15 ==0);
}
}
73 changes: 73 additions & 0 deletions src/main/java/com/dtcc/exams/part2/ArrayUtility.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.dtcc.exams.part2;

import java.lang.reflect.Array;
import java.util.*;

public class ArrayUtility<E>{

private Object[] arr;
private Integer length;

// constructor
public <E> ArrayUtility(E[] array){
// Creates a new Object array of specified length
arr = array;
length = array.length;
}

public Object[] getArr() {
return arr;
}

public Integer countDuplicatesInMerge(E[] arrayToMerge, E valueToEvaluate){
Integer count = 0;
E[] result = (E[]) new Object[this.length+ arrayToMerge.length];
System.arraycopy(this.arr, 0, result,0, this.arr.length);
System.arraycopy(arrayToMerge,0,result, this.arr.length, arrayToMerge.length);

System.out.println(Arrays.toString(result));
for(int i =0; i < result.length; i++){
if(result[i] == valueToEvaluate){
count +=1;
}
}

return count;
}
public E getMostCommonFromMerge(E[] arrayToMerge, E valueToEvaluate){
E[] result = (E[]) new Object[this.length+ arrayToMerge.length];
System.arraycopy(this.arr, 0, result,0, this.arr.length);
System.arraycopy(arrayToMerge,0,result, this.arr.length, arrayToMerge.length);
Map<E, Integer> map = new TreeMap<>();
for(E val:result){
Integer count = map.get(val);
map.put(val, count != null ? count+1 : 1);
}
return valueToEvaluate;
}

public Integer getNumberOfOccurrences(E value){
Integer count = 0;
E[] temp = (E[]) new Object[this.length];
System.arraycopy(this.arr, 0, temp,0, this.arr.length);
for(E val:temp){
if(val==value){
count+=1;
}
}
return count;
}

public E[] removeValue(E valueToRemove){
E[] testing = (E[]) new Object[this.length];
System.arraycopy(this.arr, 0, testing,0, this.arr.length);

int index = 0;
for (int i=0; i<testing.length; i++) {
if (testing[i] != valueToRemove) {
testing[index++] = testing[i];
}
}
return Arrays.copyOf(testing, index);
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/dtcc/exams/part3/RockPaperScissors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.dtcc.exams.part3;

public enum RockPaperScissors {
ROCK, PAPER, SCISSORS;

RockPaperScissors(){}

public RockPaperScissors getWinningSign(){
if(this.equals(ROCK)){
return PAPER;
}else if(this.equals(PAPER)){
return SCISSORS;
}else{
return ROCK;
}
}

public RockPaperScissors getLosingSign(){
if(this.equals(ROCK)){
return SCISSORS;
}else if(this.equals(PAPER)){
return ROCK;
}else{
return PAPER;
}
}
}
33 changes: 32 additions & 1 deletion src/main/java/com/dtcc/exams/part4/Geometry.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
package com.dtcc.exams.part4;

public class Geometry {
public class Geometry implements Circle,Rectangle{
int radius;
int height;
int width;

public Geometry(){
this(0,0,0);
}

public Geometry(int height, int width, int radius){
this.radius = radius;
this.height = height;
this.width = width;
}

public int getArea(int height, int width){
return area(height, width);

}

public double getArea(int radius){
return area(radius);

}

public double area(int radius){
return (radius*radius*3.14);
}

public int area(int height, int width) {
return (int)(width * height);
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/dtcc/exams/part5/ElectionLand.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
package com.dtcc.exams.part5;

import java.util.Map;
import java.util.TreeMap;

public class ElectionLand {

public static Map<String, Integer> tally;
//Use tree for alphabetical sorting
public ElectionLand(){
tally = new TreeMap<>();
}

public String electionWinner(String[] votes){
String winner = null;
int tempCount = 0;

//Counts up votes for each
for(String temp:votes){
if(tally.containsKey(temp)){
tally.replace(temp, tally.get(temp) + 1);
}else{
tally.put(temp, 1);
}
}

//Get last with most
for(Map.Entry m: tally.entrySet()) {
if ((int)m.getValue() >= tempCount) {
tempCount = (int)m.getValue();
winner = (String)m.getKey();
}
}
return winner;
}
}
24 changes: 24 additions & 0 deletions src/main/java/com/dtcc/exams/part6/LoveLetter.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
package com.dtcc.exams.part6;

public class LoveLetter {

public Integer[] mystery(String[] input){
int l = input.length;
Integer[] result = new Integer[input.length];

//Cycle through each input item
for(int i = 0; i < l; i++){
String s = input[i];
int count = 0;

// Track from beginning and end;
int j = 0;
int k = s.length() - 1;

//Go until we hit center
while(j < k){
count += Math.abs(s.charAt(j) - s.charAt(k));
j++;
k--;
}
result[i] = count;
}
return result;
}
}
35 changes: 35 additions & 0 deletions src/main/java/com/dtcc/exams/part7/FindTheWinner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.dtcc.exams.part7;

public class FindTheWinner {

private String winner;

public FindTheWinner(){
this.winner = null;
}

public void setWinner(String val){
this.winner = val;
}
public String getWinner(){
return this.winner;
}

public String winner(Integer[]zan, Integer[] brian, String input){
int zScore=0;
int bScore=0;
for(int i = 0; i < brian.length;i++){
if(i%2 ==0 && input.equals("Even")){
zScore += zan[i]-brian[i];
bScore += brian[i]-zan[i];
}else if(i%2 !=0 && input.equals("Odd")){
zScore += Integer.valueOf(zan[i]-brian[i]);
bScore += brian[i]-zan[i];
System.out.println(zScore);
}
}
String winn = (zScore > bScore)?"Zan" : "Brian";
this.setWinner(winn);
return this.getWinner();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dtcc.exams.assessment.part2;
/*

import com.dtcc.exams.part2.ArrayUtility;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -71,4 +72,3 @@ public void objectTest() {
Assert.assertEquals(expected, actual);
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dtcc.exams.assessment.part2;
/*

import com.dtcc.exams.part2.ArrayUtility;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -66,4 +67,3 @@ public void objectTest() {
Assert.assertEquals(expected, actual);
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dtcc.exams.assessment.part2;
/*

import com.dtcc.exams.part2.ArrayUtility;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -64,4 +65,3 @@ public void objectTest() {
Assert.assertEquals(expected, actual);
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dtcc.exams.assessment.part2;
/*

import com.dtcc.exams.UnitTestingUtils;
import com.dtcc.exams.part2.ArrayUtility;
import org.junit.Test;

public class RemoveValueTest {
Expand Down Expand Up @@ -71,4 +72,3 @@ public void objectTest() {
UnitTestingUtils.assertArrayEquality(expected, actual);
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.dtcc.exams.assessment.part3;
/*
import com.dtcc.exams.part3.RockPaperScissors;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -24,4 +24,3 @@ public void evaluateLoserTest() {
Assert.assertEquals(expected, actual);
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.dtcc.exams.assessment.part3;

/*
import org.junit.Assert;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

package com.dtcc.exams.assessment.part4;
/*

import com.dtcc.exams.part4.Geometry;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -81,4 +82,3 @@ public int compare(Class o1, Class o2) {
}

}
*/
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.dtcc.exams.assessment.part5;
/*

import com.dtcc.exams.part5.ElectionLand;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -49,4 +49,3 @@ public void electionWinnerTest4(){
}

}
*/
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.dtcc.exams.assessment.part6;
/*

import com.dtcc.exams.part6.LoveLetter;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -44,5 +44,4 @@ public void mysteryTest3(){
Assert.assertArrayEquals(expected, actual);
}

}
*/
}
Loading