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

all tests pass #64

Open
wants to merge 3 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
32 changes: 28 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,46 @@
package rocks.zipcode.quiz4.arrays;

import java.util.Arrays;
import java.util.Stack;

/**
* @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[] addElement(String[] arr, String str){
String[] result = new String[arr.length+1];
int counter = 0;
for(String existing : arr){
result[counter] = existing;
counter++;
}
result[result.length-1] = str;
return result;
}

public static String[] removeMiddleElement(String[] values) {
return null;
String[] answer = new String[0];
for (int i = 0; i < values.length;i++){
if (i!= values.length/2){
answer = addElement(answer,values[i]);
}
}
return answer;
}

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

public static String[] removeLastElement(String[] values) {
return null;
String[] result = new String[values.length-1];
for(int i = 0;i<values.length-1;i++){
result[i] = values[i];
}
return result;
}
}
12 changes: 10 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,20 @@
package rocks.zipcode.quiz4.collections;

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

public class WordCounter {
HashMap<String, Integer> countMap;

public WordCounter(String... strings) {
this.countMap = new HashMap<>();
for(String str : strings){
countMap.put(str,Collections.frequency(Arrays.asList(strings),str));
}
}

public Map<String, Integer> getWordCountMap() {
return null;
return this.countMap;
}
}
14 changes: 12 additions & 2 deletions src/main/java/rocks/zipcode/quiz4/collections/culonary/Curry.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
package rocks.zipcode.quiz4.collections.culonary;

public class Curry {
}
public class Curry implements Spice{
String name = "Curry";

public String getName(){
return this.name;
}

public void setName(String name) {
this.name = name;
}

}
26 changes: 21 additions & 5 deletions src/main/java/rocks/zipcode/quiz4/collections/culonary/Food.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
package rocks.zipcode.quiz4.collections.culonary;

import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* @author leon on 27/12/2018.
*/
public class Food {
public List<Spice> getAllSpices() {
return null;
ArrayList<Spice> added;

public Food(){
this.added = new ArrayList<Spice>();

}
public List getAllSpices() {
return added;
}

public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {
return null;
HashMap<SpiceType, Integer> spiceMap = new HashMap<>();
for(Spice currentSpice : added){
//achieved casting w/ help from classmate
SpiceType spice = (SpiceType)currentSpice.getClass();
spiceMap.put(spice,added.size());
}
System.out.println(spiceMap.keySet());

return spiceMap;
}

public void applySpice(Spice spice) {
added.add(spice);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@
/**
* @author leon on 27/12/2018.
*/
public class Ginger {
public class Ginger implements Spice{
String name = "Ginger";


public String getName(){
return this.name;
}

public void setName(String name) {
this.name = name;
}

}
13 changes: 11 additions & 2 deletions src/main/java/rocks/zipcode/quiz4/collections/culonary/Pepper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@
/**
* @author leon on 27/12/2018.
*/
public class Pepper {
}
public class Pepper implements Spice{
String name = "Pepper";


public String getName() {
return this.name;
}

public void setName(String name) {
this.name = 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 {

}
16 changes: 9 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,37 @@
package rocks.zipcode.quiz4.fundamentals;

import java.util.Arrays;

/**
* @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 Math.pow(value,2);
}

public static Double[] squareRoots(Double... value) {
return null;
return Arrays.stream(value).map(x -> x = squareRoot(x)).toArray(Double[]::new);
}

public static Double[] squares(Double... values) {
return null;
return Arrays.stream(values).map(x -> x = square(x)).toArray(Double[]::new);
}

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;
}
}
78 changes: 71 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,98 @@
package rocks.zipcode.quiz4.fundamentals;

import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

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

public static String capitalizeMiddleCharacter(String str) {
return null;
char[] letters = str.toCharArray();
letters[letters.length/2] = getMiddleCharacter(str).toString().toUpperCase().toCharArray()[0];
String result = "";
for(char letter : letters){
result += letter;
}
return result;
}

public static String lowerCaseMiddleCharacter(String str) {
return null;
char[] letters = str.toCharArray();
letters[letters.length/2] = getMiddleCharacter(str).toString().toLowerCase().toCharArray()[0];
String result = "";
for(char letter : letters){
result += letter;
}
return result;
}

public static Boolean isIsogram(String str) {
return null;
char[] letters = str.toCharArray();
for(int i = 0;i < letters.length;i++){
for (int j = i+1; j < letters.length;j++){
if (letters[i] == letters[j]){
return false;
}
}
}
return true;
}

public static Boolean hasDuplicateConsecutiveCharacters(String str) {
return null;
char[] letters = str.toCharArray();
for (int i = 0;i < letters.length-1;i++){
if (letters[i] == letters[i+1]){
return true;
}
}
return false;
}

public static String removeConsecutiveDuplicateCharacters(String str) {
return null;
int dupeCounter = 0;
char[] letters = str.toCharArray();
String result = "";
for (int i = 0;i< letters.length-1;i++){
int j = i+1;
dupeCounter = 0;
while (letters[i]==letters[j] && j < letters.length) {
dupeCounter++;
j++;
}
if (dupeCounter > 0){
for (int d = i; d <= i+dupeCounter; d++){
letters[d] = '5';
}
}
}
for (char letter : letters){
if (letter!='5'){
result += letter;
}
}
return result;
}

public static char caseChar(char chr){
if (Character.isLowerCase(chr)){
return String.valueOf(chr).toUpperCase().charAt(0);
} else {
return String.valueOf(chr).toLowerCase().charAt(0);
}

}
public static String invertCasing(String str) {
return null;
char[] letters = str.toCharArray();
String result = "";
for(char letter : letters){
result += caseChar(letter);
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
/**
* @author leon on 30/12/2018.
*/
public class Account extends BankAccount {
public class Account {
Long id;
double balance;



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,29 @@
package rocks.zipcode.quiz4.objectorientation.account;

import java.util.ArrayList;

/**
* @author leon on 27/12/2018.
*/
public class Bank {
ArrayList<BankAccount> accountList;

public Bank(){
this.accountList = new ArrayList<BankAccount>();
}

public BankAccount removeBankAccountByIndex(Integer indexNumber) {
return null;
BankAccount removed = accountList.get(indexNumber);
accountList.remove((int) indexNumber);
return removed;
}

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

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

}
}
}
Loading