diff --git a/src/main/java/com/dtcc/exams/part1/DelTechConcatenator.java b/src/main/java/com/dtcc/exams/part1/DelTechConcatenator.java new file mode 100644 index 0000000..ffd4d3a --- /dev/null +++ b/src/main/java/com/dtcc/exams/part1/DelTechConcatenator.java @@ -0,0 +1,24 @@ +package com.dtcc.exams.part1; + +public class DelTechConcatenator { + Integer input; + + public DelTechConcatenator(Integer input) { + this.input=input; + } + + public boolean isDel(){ + if(this.input %3 ==0){return true;} + else {return false;} + } + + public boolean isTech(){ + if(this.input % 5 ==0){return true;} + else {return false;} + } + + public boolean isDelTech(){ + if(this.input % 3 == 0 && this.input % 5 == 0){return true;} + else {return false;} + } +} diff --git a/src/main/java/com/dtcc/exams/part2/ArrayUtility.java b/src/main/java/com/dtcc/exams/part2/ArrayUtility.java new file mode 100644 index 0000000..99961d8 --- /dev/null +++ b/src/main/java/com/dtcc/exams/part2/ArrayUtility.java @@ -0,0 +1,90 @@ +package com.dtcc.exams.part2; + +import java.sql.Array; +import java.util.*; + +public class ArrayUtility { +//ArrayUtility arrayUtility = new ArrayUtility<>(inputArray); + public Object[] inputArray; + public ArrayUtility(ArrayDataType[] inputArray){ + this.inputArray=inputArray; + } + + public Integer countDuplicatesInMerge(ArrayDataType[] arrayToMerge, ArrayDataType valueToEvaluate){ + int count=0; + + for(int i=0;i map=new HashMap(); + for(int i=0;i entry : map.entrySet()) { + if (entry.getValue()==maxValueInMap) { + mostCommon=entry.getKey(); + } + } + + // return valueToEvaluate; + return mostCommon; + } + + public ArrayDataType[] removeValue(ArrayDataType valueToRemove){ + + List list=new ArrayList(); + + for(int i=0;i { + + @Override + public int compare(Geometry o1, Geometry o2) { + // return o1.getName().compareTo(o2.getName()); + String []circle=o1.getClass().getName().split("\\."); + String [] rectangle=o2.getClass().getName().split("\\."); + return circle[circle.length-1].compareTo(rectangle[rectangle.length-1]); + } +} diff --git a/src/main/java/com/dtcc/exams/part5/ElectionLand.java b/src/main/java/com/dtcc/exams/part5/ElectionLand.java index 87a1d00..34459bb 100644 --- a/src/main/java/com/dtcc/exams/part5/ElectionLand.java +++ b/src/main/java/com/dtcc/exams/part5/ElectionLand.java @@ -1,4 +1,25 @@ package com.dtcc.exams.part5; +import java.util.*; + public class ElectionLand { + + public String electionWinner(String[] votes){ + String winner=null; + TreeSet tree = new TreeSet(); + + Map map= new HashMap<>(); + for(int i=0;i e: map.entrySet()){ + if(e.getValue()==max){ + tree.add(e.getKey()); + } + } + winner=tree.last(); + return winner; + } } diff --git a/src/main/java/com/dtcc/exams/part6/LoveLetter.java b/src/main/java/com/dtcc/exams/part6/LoveLetter.java index 5901673..c0c06f4 100644 --- a/src/main/java/com/dtcc/exams/part6/LoveLetter.java +++ b/src/main/java/com/dtcc/exams/part6/LoveLetter.java @@ -1,4 +1,49 @@ package com.dtcc.exams.part6; +import java.util.ArrayList; +import java.util.Arrays; + public class LoveLetter { + + Integer[] output; + + public Integer[] mystery(String[] input){ + ArrayList list=new ArrayList<>(); + //String [] reverseString=new String[input.length]; + for(int i=0;i= 0; j--) { + strReverse += input[i].charAt(j) + ""; + } + if (strReverse.equalsIgnoreCase(input[i])) { + //reverseString[i] = "Palindrome"; + list.add(i, 0); + } + else { + int num = calculateNumber(input[i]); + list.add(i, num); + } + //reverseString[i]=strReverse; + } + Integer[] output = list.toArray(new Integer[list.size()]); + return output; + } + + public Integer calculateNumber(String input){ + int score=0; + for(int i=0,k=input.length()-1;iCharacter.getNumericValue(right)){ + score+=Character.getNumericValue(left)-Character.getNumericValue(right); + } + else{ + score+=Character.getNumericValue(right)-Character.getNumericValue(left); + } + } + return score; + } } + + diff --git a/src/main/java/com/dtcc/exams/part6/README.md b/src/main/java/com/dtcc/exams/part6/README.md index 7fc0878..adf5656 100644 --- a/src/main/java/com/dtcc/exams/part6/README.md +++ b/src/main/java/com/dtcc/exams/part6/README.md @@ -1,11 +1,14 @@ ## The Love-Letter Mystery -John wants to write a love letter to his crush in Iowa but is too shy to make it obvious. He decides to change all the words in the letter into palindromes. so it can only be deciphered by someone sufficiently intelligent, passionate, and lucky to boot. +John wants to write a love letter to his crush in Iowa but is too shy to make it obvious. + He decides to change all the words in the letter into palindromes. + so it can only be deciphered by someone sufficiently intelligent, passionate, and lucky to boot. To do this, he sets himself two 2 rules: * He can reduce the value of a letter, e.g. he can change 'd' to 'c', but he cannot change 'c' to 'd'. -* In order to form a palindrome, if can repeatedly reduce the value of any of the letters of a word, but only down to the letter 'a'. +* In order to form a palindrome, +if can repeatedly reduce the value of any of the letters of a word, but only down to the letter 'a'. Each reduction in the value of any letter counts as a single operation. diff --git a/src/main/java/com/dtcc/exams/part7/FindTheWinner.java b/src/main/java/com/dtcc/exams/part7/FindTheWinner.java new file mode 100644 index 0000000..cc08db8 --- /dev/null +++ b/src/main/java/com/dtcc/exams/part7/FindTheWinner.java @@ -0,0 +1,36 @@ +package com.dtcc.exams.part7; + +public class FindTheWinner { + + public FindTheWinner(){ + + } + public String winner(Integer[] leon,Integer[] wilhelm,String input){ + String winner=null; + Integer player1=0; + Integer player2=0; + if(input.equalsIgnoreCase("even")){ + for(int i=0;iplayer2){ winner="Zan"; } + else if(player2> player1){ winner="Brian"; } + else {winner="Tie";} + } + else if(input.equalsIgnoreCase("odd")){ + for(int i=0;iplayer2){ winner="Zan"; } + else if(player2> player1){ winner="Brian"; } + else {winner="Tie";} + } + return winner; + } +} diff --git a/src/main/java/com/dtcc/exams/part7/README.md b/src/main/java/com/dtcc/exams/part7/README.md index 28cbacc..1733ac9 100644 --- a/src/main/java/com/dtcc/exams/part7/README.md +++ b/src/main/java/com/dtcc/exams/part7/README.md @@ -1,10 +1,19 @@ ## Find the Winner! -Zan and Brian each have a deck of numbered cards in a pile face down. They play a game where they each alternately discard and flip the cards on the pile from top to bottom. At the beginning of the game, someone will call out "Even" or "Odd". The first move depends on which is called. If "Even" is called, the player's top cards are flipped so they can see the face value. If instead "Odd" is called, the top card is removed from each deck and discarded, then each flips his next card. Zan subtracts the value of Brian's card from his own and adds the result to his score. Likewise, Brian subtracts the value of Zan's card from his own and adds the result to his score. +Zan and Brian each have a deck of numbered cards in a pile face down. +They play a game where they each alternately discard and flip the cards on the pile from top to bottom. +At the beginning of the game, someone will call out "Even" or "Odd". The first move depends on which is called. +If "Even" is called, the player's top cards are flipped so they can see the face value. +If instead "Odd" is called, the top card is removed from each deck and discarded, then each flips his next card. +Zan subtracts the value of Brian's card from his own and adds the result to his score. +Likewise, Brian subtracts the value of Zan's card from his own and adds the result to his score. -From this point forward, each alternately discards then flips a card. Each time two cards are flipped, the players' scores are computed as before. Once all the cards have been played, whoever has the most points wins. You must determine the name of the winner if there is one, otherwise they tie. Return Zan, Brian or Tie. +From this point forward, each alternately discards then flips a card. +Each time two cards are flipped, the players' scores are computed as before. +Once all the cards have been played, whoever has the most points wins. +You must determine the name of the winner if there is one, otherwise they tie. Return Zan, Brian or Tie.