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
24 changes: 24 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,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;}
}
}
90 changes: 90 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,90 @@
package com.dtcc.exams.part2;

import java.sql.Array;
import java.util.*;

public class ArrayUtility<ArrayDataType> {
//ArrayUtility<Integer> 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<inputArray.length;i++){
if(inputArray[i]==valueToEvaluate){
count++;
}
}
for(int i=0;i<arrayToMerge.length;i++){
if(arrayToMerge[i]==valueToEvaluate){
count++;
}
}
return count;
}

public ArrayDataType getMostCommonFromMerge(ArrayDataType[] arrayToMerge, ArrayDataType valueToEvaluate){

Map<ArrayDataType,Integer> map=new HashMap<ArrayDataType,Integer>();
for(int i=0;i<arrayToMerge.length;i++){ //loop for ArrayToMerge
if(map.containsKey(arrayToMerge[i])){
int value= map.get(arrayToMerge[i]);
map.put(arrayToMerge[i],value+1);
}
else{
map.put(arrayToMerge[i],1);
}
}

for(int i=0;i<inputArray.length;i++){ //loop for inputarray
if(map.containsKey(inputArray[i])){
int value= map.get(inputArray[i]);
map.put((ArrayDataType) inputArray[i],value+1);
}
else{
map.put((ArrayDataType) inputArray[i],1);
}
}

int maxValueInMap=(Collections.max(map.values()));
ArrayDataType mostCommon=null;
for (Map.Entry<ArrayDataType,Integer> entry : map.entrySet()) {
if (entry.getValue()==maxValueInMap) {
mostCommon=entry.getKey();
}
}

// return valueToEvaluate;
return mostCommon;
}

public ArrayDataType[] removeValue(ArrayDataType valueToRemove){

List<ArrayDataType> list=new ArrayList<ArrayDataType>();

for(int i=0;i<inputArray.length;i++){
if(inputArray[i]!=valueToRemove){
list.add((ArrayDataType) inputArray[i]);
}
}

ArrayDataType[] arrayToSend= (ArrayDataType[]) new Object[list.size()];
arrayToSend=(ArrayDataType[]) list.toArray(arrayToSend);

return arrayToSend;

}

public Integer getNumberOfOccurrences(ArrayDataType valueToEvaluate ){
int count=0;
for(int i=0;i<inputArray.length;i++){
if(inputArray[i]==valueToEvaluate){
count++;
}
}
return count;
}
}
26 changes: 26 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,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;
}
}
30 changes: 30 additions & 0 deletions src/main/java/com/dtcc/exams/part3/Test.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
36 changes: 35 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,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;
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/dtcc/exams/part4/SortByName.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.dtcc.exams.part4;

import java.util.Comparator;

public class SortByName implements Comparator<Geometry> {

@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]);
}
}
21 changes: 21 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,25 @@
package com.dtcc.exams.part5;

import java.util.*;

public class ElectionLand {

public String electionWinner(String[] votes){
String winner=null;
TreeSet<String> tree = new TreeSet<String>();

Map<String,Integer> map= new HashMap<>();
for(int i=0;i<votes.length;i++){
map.put(votes[i], map.containsKey(votes[i]) ? map.get(votes[i]) + 1 : 1);
}
int max= Collections.max(map.values());

for(Map.Entry<String,Integer> e: map.entrySet()){
if(e.getValue()==max){
tree.add(e.getKey());
}
}
winner=tree.last();
return winner;
}
}
45 changes: 45 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,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<Integer> list=new ArrayList<>();
//String [] reverseString=new String[input.length];
for(int i=0;i<input.length;i++) {
int n = input[i].length();
String strReverse = "";
for (int j = n - 1; j >= 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;i<input.length()/2;i++,k--){
char left=input.charAt(i);
char right=input.charAt(k);
if(Character.getNumericValue(left)>Character.getNumericValue(right)){
score+=Character.getNumericValue(left)-Character.getNumericValue(right);
}
else{
score+=Character.getNumericValue(right)-Character.getNumericValue(left);
}
}
return score;
}
}


7 changes: 5 additions & 2 deletions src/main/java/com/dtcc/exams/part6/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
36 changes: 36 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,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;i<leon.length;i++){
if(i%2==0) {
player1 += leon[i] - wilhelm[i];
player2 += wilhelm[i] - leon[i];
}
}
if(player1>player2){ winner="Zan"; }
else if(player2> player1){ winner="Brian"; }
else {winner="Tie";}
}
else if(input.equalsIgnoreCase("odd")){
for(int i=0;i<leon.length;i++){
if(i%2==1) {
player1 += leon[i] - wilhelm[i];
player2 += wilhelm[i] - leon[i];
}
}
if(player1>player2){ winner="Zan"; }
else if(player2> player1){ winner="Brian"; }
else {winner="Tie";}
}
return winner;
}
}
13 changes: 11 additions & 2 deletions src/main/java/com/dtcc/exams/part7/README.md
Original file line number Diff line number Diff line change
@@ -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.



Expand Down