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 Completed #62

Open
wants to merge 5 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
18 changes: 14 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,32 @@
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;
String[] arr = new String[values.length - 1];
for (int i = 0; i < values.length / 2; i++) {
arr[i] = values[i];
}
for (int i = values.length / 2; i < arr.length; i++) {
arr[i] = values[i + 1];
}
return arr;
}

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

public static String[] removeLastElement(String[] values) {
return null;
return values = Arrays.copyOfRange(values, 0,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.HashMap;
import java.util.Map;

public class WordCounter {
Map<String, Integer>wordCount = new HashMap<String, Integer>();
public WordCounter(String... strings) {
}


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

public class Curry {
public class Curry implements Spice {
private String curry = "curry";

@Override
public String getName(){
return curry;
}
}
25 changes: 22 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,39 @@
package rocks.zipcode.quiz4.collections.culonary;

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

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

public Food(){
this.spiceList = new ArrayList<>();
this.spiceMap = new HashMap<>();
}

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

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

public Map<Class<? extends Spice>, Integer> getSpiceCount() {

return spiceMap;
}

public void applySpice(Spice spice) {
if (!spiceMap.containsKey(spice.getClass())){
spiceMap.put(spice.getClass(), 1);
}else {
int numOfSpice = spiceMap.get(spice.getClass());
spiceMap.put(spice.getClass(), numOfSpice + 1);
}
spiceList.add(spice);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
/**
* @author leon on 27/12/2018.
*/
public class Ginger {
public class Ginger implements Spice {
private String ginger = "ginger";

@Override
public String getName() {
return ginger;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
/**
* @author leon on 27/12/2018.
*/
public class Pepper {
public class Pepper implements Spice {
private String pepper = "pepper";
@Override
public String getName() {
return pepper;
}
}
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();
}
27 changes: 20 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,48 @@
package rocks.zipcode.quiz4.fundamentals;

import static java.lang.Math.sqrt;

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

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

public static Double[] squareRoots(Double... value) {
return null;

Double[] result = new Double[value.length];
for (int i = 0; i < value.length ; i++)
result[i] = Math.sqrt(value[i]);

return result;
}

public static Double[] squares(Double... values) {
return null;

Double[] result = new Double[values.length];

for (int i = 0; i < values.length ; i++)
result[i] = Math.pow(values[i], 2);
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: 42 additions & 9 deletions src/main/java/rocks/zipcode/quiz4/fundamentals/StringUtils.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,67 @@
package rocks.zipcode.quiz4.fundamentals;

import java.util.Arrays;
import java.util.HashMap;

/**
* @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();
int middle = arr.length/2;
arr[middle] = Character.toUpperCase(arr[middle]);
String result = new String(arr);
return result;
}

public static String lowerCaseMiddleCharacter(String str) {
return null;
char[] arr = str.toCharArray();
int middle = arr.length/2;
arr[middle] = Character.toLowerCase(arr[middle]);
String result = new String(arr);

return result;
}

public static Boolean isIsogram(String str) {
return null;
}
// Convert the string in lower case letters
//str = str.toLowerCase();
int len = str.length();
char arr[] = str.toCharArray();

Arrays.sort(arr);
for (int i = 0; i < len - 1; i++) {
if (arr[i] == arr[i + 1])
return false;
}
return true;
}
public static Boolean hasDuplicateConsecutiveCharacters(String str) {
return null;
return (str.matches(".*(.)\\1.*"));
}

public static String removeConsecutiveDuplicateCharacters(String str) {
return null;

//return str.replaceAll("(.+?)\\1+", "");
//return str.replaceAll("([a-zA-Z])\\1\\1+", "$1$1$1");
//return str.replaceAll("((.)\\2{2})\\2+","$1$1");
return str.replaceAll("(.)(\\1)","");
}

public static String invertCasing(String str) {
return null;
StringBuilder result = new StringBuilder(str.length());
for (char c : str.toCharArray()) {
if (Character.isUpperCase(c)) {
c = Character.toLowerCase(c);
} else if (Character.isLowerCase(c)) {
c = Character.toUpperCase(c);
}
result.append(c);
}
return result.toString();
}
}
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 Account(){}
public Long getId() {
return null;

return this.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;
import java.util.List;

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

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

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

public Boolean containsBankAccount(BankAccount bankAccount) {
throw new UnsupportedOperationException("Method not yet implemented");
return accounts.contains(bankAccount);
// throw new UnsupportedOperationException("Method not yet implemented");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,32 @@
/**
* @author leon on 27/12/2018.
*/
public class BankAccount {
public class BankAccount extends Account implements Transactable {
private double balance;

public void setBalance(Double val) {
this.balance = val;
}

@Override
public void deposit(Double amountToIncreaseBy) throws IllegalArgumentException {
if (amountToIncreaseBy < 0) {
throw new IllegalArgumentException();
}
balance += amountToIncreaseBy;
}

@Override
public void withdrawal(Double amountToDecreaseBy) throws IllegalArgumentException {
if(balance < amountToDecreaseBy || amountToDecreaseBy < 0){
throw new IllegalArgumentException();
}
balance -= amountToDecreaseBy;
}

@Override
public Double getBalance() {
return balance;
}

}
Loading