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
42 changes: 36 additions & 6 deletions src/main/java/com/dtcc/exams/arrays/IntegerArrayUtils.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package com.dtcc.exams.arrays;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class IntegerArrayUtils {
/**
* @param integerArray - array to have value added to it
* @param valueToBeAdded - value to be added to the end of the array
* @return - identical array with one additional element of `valueToBeAdded` at the end of the array
*/
public static Integer[] add(Integer[] integerArray, Integer valueToBeAdded) {
return null;
// convert the array to a list and back to array after adding
List<Integer> integerList = new ArrayList<Integer>(Arrays.asList(integerArray));
integerList.add(valueToBeAdded);
integerArray = integerList.toArray(integerArray);
return integerArray;
}

/**
Expand All @@ -17,7 +25,11 @@ public static Integer[] add(Integer[] integerArray, Integer valueToBeAdded) {
* @return `integerArray` with `valueToBeInserted` at index number `indexToInsertAt`
*/
public static Integer[] replace(Integer[] integerArray, int indexToInsertAt, Integer valueToBeInserted) {
return null;
List<Integer> integerList = new ArrayList<Integer>(Arrays.asList(integerArray));
integerList.set(indexToInsertAt, valueToBeInserted);
integerArray = integerList.toArray(integerArray);

return integerArray;
}

/**
Expand All @@ -26,30 +38,48 @@ public static Integer[] replace(Integer[] integerArray, int indexToInsertAt, Int
* @return element located at `indexToFetch`
*/
public static Integer get(Integer[] integerArray, Integer indexToFetch) {
return null;

return integerArray[indexToFetch];
}

/**
* @param integerArray - array to be evaluated
* @return identical array with even-values incremented by 1 and odd-values decremented by 1
*/
public static Integer[] incrementEvenDecrementOdd(Integer[] integerArray) {
return null;

for(int i= 0 ; i < integerArray.length; i++){
if(integerArray[i] % 2 == 0){
integerArray[i] = integerArray[i] + 1;
}
else integerArray[i] = integerArray[i] -1;
}
return integerArray;
}

/**
* @param integerArray - array to be evaluated
* @return identical array with even-values incremented by 1
*/
public static Integer[] incrementEven(Integer[] integerArray) {
return null;
for(int i= 0 ; i < integerArray.length; i++){
if(integerArray[i] % 2 == 0){
integerArray[i] = integerArray[i] + 1;
}
}
return integerArray;
}

/**
* @param input - array to be evaluated
* @return identical array with odd-values decremented by 1
*/
public static Integer[] decrementOdd(Integer[] input) {
return null;
for(int i= 0 ; i < input.length; i++){
if(input[i] % 2 != 0){
input[i] = input[i] - 1;
}
}
return input;
}
}
7 changes: 5 additions & 2 deletions src/main/java/com/dtcc/exams/arrays/StringArrayUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.dtcc.exams.arrays;

import java.util.Arrays;

public class StringArrayUtils {
/**
* @param arrayToBeSpliced - array to be evaluated
Expand All @@ -8,7 +10,7 @@ public class StringArrayUtils {
* @return an array with all elements between `startingIndex` and `endingIndex`
*/
public static String[] getSubArray(String[] arrayToBeSpliced, int startingIndex, int endingIndex) {
return null;
return Arrays.copyOfRange(arrayToBeSpliced, startingIndex,endingIndex);
}


Expand All @@ -18,6 +20,7 @@ public static String[] getSubArray(String[] arrayToBeSpliced, int startingIndex,
* @return an array all elements between after `startingIndex`
*/
public static String[] getEndingArray(String[] arrayToBeSpliced, int startingIndex) {
return null;

return Arrays.copyOfRange(arrayToBeSpliced,startingIndex,arrayToBeSpliced.length);
}
}
24 changes: 21 additions & 3 deletions src/main/java/com/dtcc/exams/atm/Account.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
package com.dtcc.exams.atm;

public class Account {


double balance;
boolean accountClosed;

public Account(double v) {
balance = v;
}

public double balance() {
return 0.0;
return balance;
}

public boolean closeAccount() {
if(balance == 0.0){
return true;
}
return false;
}

public void deposit(double v) {
balance =+ v;
}

public Double withdraw(double v) {
return 0.0;
return balance - v;
}

public void transfer(Account b, double v) {
b.balance = v;
this.balance =- v;
}

// public void setBalance(double balance){
// this.balance=balance;
// }
// public double getBalance(){
// return balance;
// }
}

4 changes: 3 additions & 1 deletion src/main/java/com/dtcc/exams/collections/Inventory.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dtcc.exams.collections;

import java.util.List;
import java.util.Map;

/**
* Use a map to keep track of inventory in a store
Expand All @@ -9,8 +10,9 @@ public class Inventory {
/**
* @param strings list of strings to add / remove / fetch from
*/
public Map<String, Integer> Integer;
public Inventory(List<String> strings) {

// List<String> list = new List<String>();
}

/**
Expand Down
34 changes: 29 additions & 5 deletions src/main/java/com/dtcc/exams/fundamentals/BasicStringUtils.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package com.dtcc.exams.fundamentals;

import java.util.regex.Pattern;

public class BasicStringUtils {
/**
* @param string1 - Base string to be added to
* @param string2 - String to add to `string1`
* @return concatenation of `string1` and `string2`
*/
public static String concatentate(String string1, String string2) {
return null;
return string1 + string2;
}

/**
* @param string1 - String to be reversed
* @return an identical string with characters in reverse order
*/
public static String reverse(String string1) {
return null;
StringBuilder emad = new StringBuilder();
emad.append(string1);
emad = emad.reverse();
string1 = emad.toString();
return string1;
}

/**
Expand All @@ -24,7 +30,16 @@ public static String reverse(String string1) {
* @return concatenation of the reverse of `string1` and reverse of `string2`
*/
public static String reverseThenConcatenate(String string1, String string2) {
return null;
StringBuilder emad = new StringBuilder();
emad.append(string1);
emad = emad.reverse();
string1 = emad.toString();

StringBuilder emad1 = new StringBuilder();
emad1.append(string2);
emad1 = emad1.reverse();
string2 = emad1.toString();
return string1 + string2;
}

/**
Expand All @@ -33,7 +48,8 @@ public static String reverseThenConcatenate(String string1, String string2) {
* @return `string` with `charactersToRemove` removed
*/
public static String removeCharacters(String string, String charactersToRemove) {
return null;

return string.replaceAll(charactersToRemove, "");
}

/**
Expand All @@ -42,6 +58,14 @@ public static String removeCharacters(String string, String charactersToRemove)
* @return reverse of `string` with `charactersToRemove` removed
*/
public static String removeCharactersThenReverse(String string, String charactersToRemove) {
return null;
string.replaceAll(charactersToRemove, "");
byte[] strAsByteArray = string.getBytes();
byte[] result = new byte[strAsByteArray.length];

for (int i = 0; i < strAsByteArray.length; i++)
result[i] = strAsByteArray[strAsByteArray.length - i - 1];

String string1 = new String(result);
return string1;
}
}
22 changes: 17 additions & 5 deletions src/main/java/com/dtcc/exams/fundamentals/PredicateUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,30 @@ public class PredicateUtilities {
* @return true if `value` is a multiple of 2
*/
public static Boolean isEven(Integer value) {
return null;
if (value % 2 == 0)
return true;
else
return false;
}

/**
* @param value - the value to be evaluated
* @return true if `value` is not a multiple of 2
*/
public static Boolean isOdd(Integer value) {
return null;
if(value % 2 != 0)
return true;
else return false;
}

/**
* @param value - the value to be evaluated
* @return true if `value` is a multiple of 3
*/
public static Boolean isMultipleOf3(Integer value) {
return null;
if(value % 3 == 0)
return true;
else return false;
}

/**
Expand All @@ -32,14 +39,19 @@ public static Boolean isMultipleOf3(Integer value) {
* @return true if `value` is a multiple of `multiple`
*/
public static Boolean isMultipleOfN(Integer value, Integer multiple) {
return null;
if(value % multiple == 0)
return true;
else return false;
}

/**
* @param string - the string to be evaluated
* @return true if `string` starts with a capital letter
*/
public static Boolean startsWithCapitalLetter(String string) {
return null;
if(Character.isUpperCase(string.charAt(0)) == true)
return true;
else
return false;
}
}
28 changes: 22 additions & 6 deletions src/main/java/com/dtcc/exams/fundamentals/StringUtils.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.dtcc.exams.fundamentals;



public class StringUtils {
/**
* @param stringToBePadded - string value to be flushed right
* @param amountOfPadding - amount of padding to be flushed left
* @return `stringToBePadded` flushed right by left-padding
*/
public static String padLeft(String stringToBePadded, int amountOfPadding) {
return null;

return String.format("%" + amountOfPadding + "s", stringToBePadded);
}

/**
Expand All @@ -17,7 +19,7 @@ public static String padLeft(String stringToBePadded, int amountOfPadding) {
* @return `stringToBePadded` flushed right by right-padding
*/
public static String padRight(String stringToBePadded, int amountOfPadding) {
return null;
return String.format("%" + -amountOfPadding + "s", stringToBePadded);
}

/**
Expand All @@ -26,30 +28,44 @@ public static String padRight(String stringToBePadded, int amountOfPadding) {
* @return the string repeated and concatenated `n` times
*/
public static String repeatString(String stringToBeRepeated, int numberOfTimeToRepeat) {
return null;
String repeated = new String(new char[numberOfTimeToRepeat]).replace("\0", stringToBeRepeated);
return repeated;
}

/**
* @param string - string to be evaluated
* @return - true if string only contains alpha characters
*/
public static Boolean isAlphaString(String string) {
return null;
string = string.replaceAll("\\s+", "");
if(string.chars().allMatch(Character::isLetter))
return true;
else
return false;
}

/**
* @param string - string to be evaluated
* @return - true if string only contains numeric characters
*/
public static Boolean isNumericString(String string) {
return null;
string = string.replaceAll("\\s+", "");
if(string.chars().allMatch(Character::isDigit))
return true;
else
return false;
}

/**
* @param string - string to be evaluated
* @return - true if string only contains special characters
*/
public static Boolean isSpecialCharacterString(String string) {
return null;
string = string.replaceAll("\\s+", "");
if(string != null && string.chars().noneMatch(Character::isAlphabetic) && string.chars().noneMatch(Character::isDigit))
return true;
else
return false;

}
}
Loading