Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

done #65

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

done #65

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
26 changes: 22 additions & 4 deletions src/main/java/rocks/zipcode/quiz4/arrays/ArrayUtils.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
package rocks.zipcode.quiz4.arrays;

import rocks.zipcode.quiz4.fundamentals.StringUtils;

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

/**
* @author leon on 01/01/2019.
*/
public class ArrayUtils {
public static String getMiddleElement(String[] values) {
return null;
return values[values.length/2];
}

public static String[] removeMiddleElement(String[] values) {
return null;
List<String> list = new ArrayList<>(Arrays.asList(values));
list.remove(list.size()/2);
return listToStringArr(list);
}

public static String getLastElement(String[] values) {
return null;
return values[values.length-1];
}

public static String[] removeLastElement(String[] values) {
return null;
Deque<String> list = new ArrayDeque<>(Arrays.asList(values));
list.removeLast();
String[] result = new String[list.size()];
result = list.toArray(result);
return result;
}

public static String[] listToStringArr(List<String> list){
String[] result = new String[list.size()];
result = list.toArray(result);
return result;
}

}
22 changes: 20 additions & 2 deletions src/main/java/rocks/zipcode/quiz4/collections/WordCounter.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
package rocks.zipcode.quiz4.collections;

import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

public class WordCounter {
private Map<String, Integer> wordsMap;
private List<String> wordsList;

public WordCounter(String... strings) {
wordsMap = new HashMap<>();
wordsList = Arrays
.stream(strings)
.collect(Collectors.toCollection(ArrayList::new));

}

public Map<String, Integer> getWordCountMap() {
return null;
for(String s : wordsList){
if(!wordsMap.containsKey(s)){
wordsMap.put(s,1);
}
else{
int count = wordsMap.get(s);
wordsMap.put(s, count+1);
}
}
return wordsMap;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
package rocks.zipcode.quiz4.collections.culonary;

public class Curry {
public class Curry implements Spice{


@Override
public String getName() {

return this.getClass().toString();
}
}
27 changes: 25 additions & 2 deletions src/main/java/rocks/zipcode/quiz4/collections/culonary/Food.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
package rocks.zipcode.quiz4.collections.culonary;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
* @author leon on 27/12/2018.
*/
public class Food {
private List<Spice> spices;


public Food(){
spices = new ArrayList<>();

}

public List<Spice> getAllSpices() {
return null;

return spices;
}

public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {
return null;
Map<SpiceType, Integer> spiceMap = new HashMap<>();
spices.forEach(s -> spiceMap.compute((SpiceType) s.getClass(), (k, v) -> (v == null) ? 1 : v + 1));
return spiceMap;
}



public void applySpice(Spice spice) {
spices.add(spice);


}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
/**
* @author leon on 27/12/2018.
*/
public class Ginger {
public class Ginger implements Spice{


@Override
public String getName() {

return this.getClass().toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
/**
* @author leon on 27/12/2018.
*/
public class Pepper {
public class Pepper implements Spice{



@Override
public String getName() {
return this.getClass().toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
* @author leon on 27/12/2018.
*/
public interface Spice {
String getName();
}
39 changes: 32 additions & 7 deletions src/main/java/rocks/zipcode/quiz4/fundamentals/Calculator.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,60 @@
package rocks.zipcode.quiz4.fundamentals;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author leon on 21/12/2018.
*/
public class Calculator {
public static Double squareRoot(Double value) {
return null;

return Math.sqrt(value);
}

public static Double square(Double value) {
return null;

return value*value;
}

public static Double[] squareRoots(Double... value) {
return null;
List<Double> list = Arrays
.stream(value)
.map(Math::sqrt)
.collect(Collectors.toCollection(ArrayList::new));
Double[] result = new Double[list.size()];
result = list.toArray(result);
return result;
}

public static Double[] squares(Double... values) {
return null;
List<Double> list = Arrays
.stream(values)
.map(d->d*d)
.collect(Collectors.toCollection(ArrayList::new));
Double[] result = new Double[list.size()];
result = list.toArray(result);
return result;
}

public static Double add(Double value1, Double value2) {
return null;

return value1+value2;
}

public static Double subtract(Double value1, Double value2) {
return null;

return value1-value2;
}


public static Double divide(Double divisor, Double dividend) {
return null;

return divisor/dividend;
}


}
51 changes: 44 additions & 7 deletions src/main/java/rocks/zipcode/quiz4/fundamentals/StringUtils.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,71 @@
package rocks.zipcode.quiz4.fundamentals;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* @author leon on 21/12/2018.
*/
public class StringUtils {
public static Character getMiddleCharacter(String string) {
return null;
return string.charAt(string.length()/2);
}

public static String capitalizeMiddleCharacter(String str) {
return null;
StringBuilder sb = new StringBuilder(str);
sb.setCharAt(str.length()/2, Character.toUpperCase(getMiddleCharacter(str)));
return sb.toString();
}

public static String lowerCaseMiddleCharacter(String str) {
return null;
StringBuilder sb = new StringBuilder(str);
sb.setCharAt(str.length()/2, Character.toLowerCase(getMiddleCharacter(str)));
return sb.toString();
}

public static Boolean isIsogram(String str) {
return null;
return stringToCharList(str).stream().allMatch(new HashSet<>()::add);
}

public static Boolean hasDuplicateConsecutiveCharacters(String str) {
return null;
return (str.matches(".*(.)\\1.*"));
}

public static String removeConsecutiveDuplicateCharacters(String str) {
return null;
StringBuilder sb = new StringBuilder(str);
int count = 0;
while (count < sb.length() -1){
if(sb.charAt(count) == sb.charAt(count+1)){
sb.deleteCharAt(count);
sb.deleteCharAt(count);
}
count+=1;
}
return sb.toString();

}

public static String invertCasing(String str) {
return null;
StringBuilder sb = new StringBuilder();
for (Character c : stringToCharList(str)){
if(Character.toUpperCase(c) == c){
c = Character.toLowerCase(c);
}
else {
c = Character.toUpperCase(c);
}
sb.append(c);
}
return sb.toString();
}

public static List<Character> stringToCharList(String s){
return s.chars().mapToObj((i) -> (char) i).collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
/**
* @author leon on 30/12/2018.
*/
public class Account extends BankAccount {
public class Account {
private Long id;

public Long getId() {
return null;

return id;
}

public void setId(Long id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
package rocks.zipcode.quiz4.objectorientation.account;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author leon on 27/12/2018.
*/
public class Bank {
private List<BankAccount> accounts = new ArrayList<>();

public BankAccount removeBankAccountByIndex(Integer indexNumber) {
return null;
BankAccount toBeRemoved = accounts.get(indexNumber);
accounts = accounts.stream().filter(a -> a != toBeRemoved).collect(Collectors.toList());
return toBeRemoved;
}

public void addBankAccount(BankAccount bankAccount) {
accounts.add(bankAccount);
}

public Boolean containsBankAccount(BankAccount bankAccount) {
throw new UnsupportedOperationException("Method not yet implemented");
return accounts.contains(bankAccount);
}


}
Loading