From 90b0beb3d1416f5d0ce3f0329697a161787c2249 Mon Sep 17 00:00:00 2001 From: charujamnis Date: Thu, 15 Oct 2020 17:49:14 -0400 Subject: [PATCH 1/2] java files added --- .../dtcc/exams/part1/DelTechConcatenator.java | 24 ++++++++++ .../com/dtcc/exams/part2/ArrayUtility.java | 40 +++++++++++++++++ .../dtcc/exams/part3/RockPaperScissors.java | 26 +++++++++++ src/main/java/com/dtcc/exams/part3/Test.java | 30 +++++++++++++ .../java/com/dtcc/exams/part4/Geometry.java | 36 ++++++++++++++- .../java/com/dtcc/exams/part4/SortByName.java | 14 ++++++ .../com/dtcc/exams/part5/ElectionLand.java | 21 +++++++++ .../java/com/dtcc/exams/part6/LoveLetter.java | 45 +++++++++++++++++++ src/main/java/com/dtcc/exams/part6/README.md | 7 ++- .../com/dtcc/exams/part7/FindTheWinner.java | 36 +++++++++++++++ src/main/java/com/dtcc/exams/part7/README.md | 13 +++++- 11 files changed, 287 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/dtcc/exams/part1/DelTechConcatenator.java create mode 100644 src/main/java/com/dtcc/exams/part2/ArrayUtility.java create mode 100644 src/main/java/com/dtcc/exams/part3/RockPaperScissors.java create mode 100644 src/main/java/com/dtcc/exams/part3/Test.java create mode 100644 src/main/java/com/dtcc/exams/part4/SortByName.java create mode 100644 src/main/java/com/dtcc/exams/part7/FindTheWinner.java 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..a80ed2d --- /dev/null +++ b/src/main/java/com/dtcc/exams/part2/ArrayUtility.java @@ -0,0 +1,40 @@ +package com.dtcc.exams.part2; + +public class ArrayUtility { + // ArrayUtility arrayUtility = new ArrayUtility<>(inputArray); + Object[] inputArray; + + public ArrayUtility(Integer[] inputArray){ + this.inputArray=inputArray; + } + + public Integer countDuplicatesInMerge(Integer[] arrayToMerge, Integer valueToEvaluate){ + + return 0; + } + + public Integer countDuplicatesInMerge(Long[] arrayToMerge, Integer valueToEvaluate){ + + return 0; + } + + public Integer countDuplicatesInMerge(String[] arrayToMerge, Integer valueToEvaluate){ + + return 0; + } + + public Integer countDuplicatesInMerge(Object[] arrayToMerge, Integer valueToEvaluate){ + + return 0; + } + + public Object[] removeValue(Object valueToRemove){ + + return inputArray; + } + + // Long actual = arrayUtility.getMostCommonFromMerge(arrayToMerge, expected); + public Integer getMostCommonFromMerge(Object arrayToMerge, Integer valueToEvaluate ){ + return 0; + } +} diff --git a/src/main/java/com/dtcc/exams/part3/RockPaperScissors.java b/src/main/java/com/dtcc/exams/part3/RockPaperScissors.java new file mode 100644 index 0000000..c3ce393 --- /dev/null +++ b/src/main/java/com/dtcc/exams/part3/RockPaperScissors.java @@ -0,0 +1,26 @@ +package com.dtcc.exams.part3; + +public enum RockPaperScissors{ + ROCK, + PAPER , + SCISSORS; + + RockPaperScissors rockpaperscissors; + + private RockPaperScissors(){ + } + + public RockPaperScissors getWinningSign() { + if(this == RockPaperScissors.PAPER){ rockpaperscissors=RockPaperScissors.SCISSORS;} + else if(this == RockPaperScissors.ROCK){ rockpaperscissors=RockPaperScissors.PAPER;} + else if(this == RockPaperScissors.SCISSORS){ rockpaperscissors=RockPaperScissors.ROCK;} + return rockpaperscissors; + } + + public RockPaperScissors getLosingSign() { + if(this == RockPaperScissors.PAPER){ rockpaperscissors=RockPaperScissors.ROCK;} + else if(this == RockPaperScissors.ROCK){ rockpaperscissors=RockPaperScissors.SCISSORS;} + else if(this == RockPaperScissors.SCISSORS){ rockpaperscissors=RockPaperScissors.PAPER;} + return rockpaperscissors; + } +} diff --git a/src/main/java/com/dtcc/exams/part3/Test.java b/src/main/java/com/dtcc/exams/part3/Test.java new file mode 100644 index 0000000..94b38ae --- /dev/null +++ b/src/main/java/com/dtcc/exams/part3/Test.java @@ -0,0 +1,30 @@ +package com.dtcc.exams.part3; + +enum Color +{ + RED, GREEN, BLUE; + + // enum constructor called separately for each + // constant + private Color() + { + System.out.println("Constructor called for : " + + this.toString()); + } + + public void colorInfo() + { + System.out.println("Universal Color"); + } +} + +public class Test +{ + // Driver method + public static void main(String[] args) + { + Color c1 = Color.RED; + System.out.println(c1); + c1.colorInfo(); + } +} \ No newline at end of file diff --git a/src/main/java/com/dtcc/exams/part4/Geometry.java b/src/main/java/com/dtcc/exams/part4/Geometry.java index bbe2576..b81f76e 100644 --- a/src/main/java/com/dtcc/exams/part4/Geometry.java +++ b/src/main/java/com/dtcc/exams/part4/Geometry.java @@ -1,4 +1,38 @@ package com.dtcc.exams.part4; -public class Geometry { +public class Geometry implements Circle, Rectangle{ + int height; + int width; + int radius; + + public Geometry(){ + + } + public Geometry(int height, int width, int radius){ + this.height=height; + this.width=width; + this.radius=radius; + } + + @Override + public double area(int radius) { + return 0; + } + + @Override + public int area(int height, int width) { + return 0; + } + + public double getArea(int radius) { + double area; + area=3.14*radius*radius; + return area; + } + + public int getArea(int height,int width) { + int area; + area=height*width; + return area; + } } diff --git a/src/main/java/com/dtcc/exams/part4/SortByName.java b/src/main/java/com/dtcc/exams/part4/SortByName.java new file mode 100644 index 0000000..a3a68bb --- /dev/null +++ b/src/main/java/com/dtcc/exams/part4/SortByName.java @@ -0,0 +1,14 @@ +package com.dtcc.exams.part4; + +import java.util.Comparator; + +public class SortByName implements Comparator { + + @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. From a97fe73e3cdcc55f0e236d33e0aac8fb1800ec98 Mon Sep 17 00:00:00 2001 From: charujamnis Date: Fri, 6 Nov 2020 12:25:23 -0500 Subject: [PATCH 2/2] ArrayUtility.java added --- .../com/dtcc/exams/part2/ArrayUtility.java | 92 ++++++++++++++----- 1 file changed, 71 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/dtcc/exams/part2/ArrayUtility.java b/src/main/java/com/dtcc/exams/part2/ArrayUtility.java index a80ed2d..99961d8 100644 --- a/src/main/java/com/dtcc/exams/part2/ArrayUtility.java +++ b/src/main/java/com/dtcc/exams/part2/ArrayUtility.java @@ -1,40 +1,90 @@ package com.dtcc.exams.part2; -public class ArrayUtility { - // ArrayUtility arrayUtility = new ArrayUtility<>(inputArray); - Object[] inputArray; +import java.sql.Array; +import java.util.*; - public ArrayUtility(Integer[] inputArray){ - this.inputArray=inputArray; - } +public class ArrayUtility { +//ArrayUtility arrayUtility = new ArrayUtility<>(inputArray); + public Object[] inputArray; + public ArrayUtility(ArrayDataType[] inputArray){ + this.inputArray=inputArray; + } - public Integer countDuplicatesInMerge(Integer[] arrayToMerge, Integer valueToEvaluate){ + public Integer countDuplicatesInMerge(ArrayDataType[] arrayToMerge, ArrayDataType valueToEvaluate){ + int count=0; - return 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 0; + // return valueToEvaluate; + return mostCommon; } - public Integer countDuplicatesInMerge(Object[] arrayToMerge, Integer valueToEvaluate){ + public ArrayDataType[] removeValue(ArrayDataType valueToRemove){ - return 0; - } + List list=new ArrayList(); + + for(int i=0;i