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

quiz done #57

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
16 changes: 12 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,30 @@
package rocks.zipcode.quiz4.arrays;

import java.util.Arrays;

/**
* @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;

int middle = values.length/2;
for (int i = middle; i<values.length-1; i++) {
values[i] = values[i+1];
}
return Arrays.copyOf(values,values.length-1);

}

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

public static String[] removeLastElement(String[] values) {
return null;
return Arrays.copyOf(values,values.length-1);
}
}
15 changes: 13 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,23 @@
package rocks.zipcode.quiz4.collections;

import java.util.Map;
import java.util.*;

public class WordCounter {
private List<String> words;
public WordCounter(String... strings) {
words = Arrays.asList(strings);
}
public WordCounter() {
words = new ArrayList<>();
}


public Map<String, Integer> getWordCountMap() {
return null;

Map<String, Integer> frequencyMap = new HashMap<>();
for(String word : words) {
frequencyMap.put(word, Collections.frequency(words, word));
}
return frequencyMap;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
package rocks.zipcode.quiz4.collections.culonary;

public class Curry {
import java.util.Objects;

public class Curry implements Spice{
private String name ="curry";
@Override
public String getName() {
return name;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Curry)) return false;
Curry curry = (Curry) o;
return Objects.equals(name, curry.name);
}

@Override
public int hashCode() {
return Objects.hash(name);
}
}
28 changes: 25 additions & 3 deletions src/main/java/rocks/zipcode/quiz4/collections/culonary/Food.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
package rocks.zipcode.quiz4.collections.culonary;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
* @author leon on 27/12/2018.
*/
public class Food {
Map<Class<? extends Spice>, Integer> spiceMap;
List<Spice> spices;

public Food(){
this(null);
}

public Food(Map<Class<? extends Spice>, Integer> spiceMap) {
if(spiceMap != null)
this.spiceMap = spiceMap;
else
this.spiceMap = new LinkedHashMap<>();
spices = new ArrayList<>();
}

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

public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {
return null;
public <SpiceType extends Class<? extends Spice>> Map<Class<? extends Spice>, Integer> getSpiceCount() {
//public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {
return spiceMap;
}

public void applySpice(Spice spice) {
Integer frequency = spiceMap.getOrDefault(spice.getClass(), null);
frequency = (frequency == null)? 1: frequency+1;
spiceMap.put(spice.getClass(), frequency);
spices.add(spice);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
package rocks.zipcode.quiz4.collections.culonary;

import java.util.Objects;

/**
* @author leon on 27/12/2018.
*/
public class Ginger {
public class Ginger implements Spice{
private String name ="ginger";
@Override
public String getName() {
return name;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Ginger)) return false;
Ginger ginger = (Ginger) o;
return Objects.equals(name, ginger.name);
}

@Override
public int hashCode() {
return Objects.hash(name);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
package rocks.zipcode.quiz4.collections.culonary;

import java.util.Objects;

/**
* @author leon on 27/12/2018.
*/
public class Pepper {
public class Pepper implements Spice{
private String name ="pepper";
@Override
public String getName() {
return name;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Pepper)) return false;
Pepper pepper = (Pepper) o;
return Objects.equals(name, pepper.name);
}
}
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 {
public String getName();
}
23 changes: 15 additions & 8 deletions src/main/java/rocks/zipcode/quiz4/fundamentals/Calculator.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
package rocks.zipcode.quiz4.fundamentals;

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> squareRoots = Arrays.stream(value).map(number -> Math.sqrt(number))
.collect(Collectors.toList());
return squareRoots.toArray(new Double[squareRoots.size()]);}

public static Double[] squares(Double... values) {
return null;
List<Double> squareRoots = Arrays.stream(values).map(number -> number * number)
.collect(Collectors.toList());
return squareRoots.toArray(new Double[squareRoots.size()]);
}

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;
}
}
68 changes: 61 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,88 @@
package rocks.zipcode.quiz4.fundamentals;

import java.util.List;
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;
char[] arr = str.toCharArray();
arr[arr.length/2] = String.valueOf(getMiddleCharacter(str)).toUpperCase().charAt(0);
return new String(arr);
}

public static String lowerCaseMiddleCharacter(String str) {
return null;
char[] arr = str.toCharArray();
arr[arr.length/2] = String.valueOf(getMiddleCharacter(str)).toLowerCase().charAt(0);
return new String(arr);
}

public static Boolean isIsogram(String str) {
return null;
Stream<Character> characterStream = str.chars()
.mapToObj(c -> (char) c);
List<Character> list = characterStream
.filter(value -> frequency(str, (char)value) != 1)
.collect(Collectors.toList());
return list.size()==0;
}

public static Integer frequency(String str, char toFind){
Stream<Character> characterStream = str.chars()
.mapToObj(c -> (char) c);
List<Character> list = characterStream
.filter(value -> (char) value == toFind)
.collect(Collectors.toList());
return list.size();
}

public static Boolean hasDuplicateConsecutiveCharacters(String str) {
return null;
boolean hasDuplicates = false;
for(int i = 0; i < str.length() - 1; i++){
if(str.charAt(i) == str.charAt(i + 1))
{
hasDuplicates = true;
break;
}
}
return hasDuplicates;
}

public static String removeConsecutiveDuplicateCharacters(String str) {
return null;
String result = "";

for(int i = 0; i < str.length();){
char character = str.charAt(i);
int j = i+ 1;
for( ; j < str.length();){
if(str.charAt(j) == character){
j++;
}
else
break;
}
if(j == i + 1) {
result += String.valueOf(character);
}
i = j;
}
return result;
}

public static String invertCasing(String str) {
return null;
String result = "";
for(int i = 0; i < str.length(); i++){
char ch = str.charAt(i);
result += Character.isLowerCase(ch) ?
String.valueOf(Character.toUpperCase(ch)) :
String.valueOf(Character.toLowerCase(ch));
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
/**
* @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,27 @@
package rocks.zipcode.quiz4.objectorientation.account;

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

/**
* @author leon on 27/12/2018.
*/
public class Bank {
public BankAccount removeBankAccountByIndex(Integer indexNumber) {
return null;
private List<BankAccount> accounts;

public Bank() {
this.accounts = new ArrayList<>();
}
public Boolean removeBankAccountByIndex(Integer indexNumber) {
return accounts.remove(accounts.get(indexNumber));
}

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

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