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

Finished #74

Open
wants to merge 9 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
23 changes: 19 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,37 @@
package rocks.zipcode.quiz4.arrays;

import java.util.ArrayList;
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;

ArrayList<String> newArr = new ArrayList<>(Arrays.asList(values));
newArr.remove(getMiddleElement(values));
values = new String[newArr.size()];
newArr.toArray(values);
return values;
}

public static String getLastElement(String[] values) {
return null;

return values[values.length - 1];
}

public static String[] removeLastElement(String[] values) {
return null;
// ArrayList<String> newArr = new ArrayList<>(Arrays.asList(values));
// newArr.remove(getLastElement(values));
// values = new String[newArr.size()];
// newArr.toArray(values);
// return values;

return Arrays.copyOfRange(values,0,values.length - 1);
}
}
14 changes: 13 additions & 1 deletion src/main/java/rocks/zipcode/quiz4/collections/WordCounter.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
package rocks.zipcode.quiz4.collections;

import java.util.HashMap;
import java.util.Map;

public class WordCounter {

private HashMap<String, Integer> wordCount = new HashMap<>();

public WordCounter(String... strings) {
for(String str : strings){
if(!this.wordCount.keySet().contains(str)){
this.wordCount.put(str, 1);
}
else {
this.wordCount.replace(str, this.wordCount.get(str) + 1);
}
}
}

public Map<String, Integer> getWordCountMap() {
return null;
return this.wordCount;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
package rocks.zipcode.quiz4.collections.culonary;

public class Curry {
public class Curry implements Spice{
String name;

public Curry() {
this.name = null;
}

public Curry(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
23 changes: 21 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,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 {

List<Spice> spices;

public Food() {
this.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> spiceCountMap = new HashMap<>();
for (Spice spice : spices) {
SpiceType type = (SpiceType) spice.getClass();
if(spiceCountMap.putIfAbsent(type, 1) != null) {
Integer count = spiceCountMap.get(type) + 1;
spiceCountMap.replace(type, count);
}
}
return spiceCountMap;
}

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

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

public Ginger() {
this.name = null;
}

public Ginger(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,22 @@
/**
* @author leon on 27/12/2018.
*/
public class Pepper {
public class Pepper implements Spice{
String name;

public Pepper() {
this.name = null;
}

public Pepper(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
23 changes: 16 additions & 7 deletions src/main/java/rocks/zipcode/quiz4/fundamentals/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,40 @@
*/
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;
Double[] sqArr = new Double[value.length];
for(int i = 0; i < value.length; i++){
sqArr[i] = Math.sqrt(value[i]);
}
return sqArr;
}

public static Double[] squares(Double... values) {
return null;
Double[] sqArr = new Double[values.length];
for(int i = 0; i < values.length; i++){
sqArr[i] = (values[i] * values[i]);
}
return sqArr;
}

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;
}
}
57 changes: 50 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,77 @@
package rocks.zipcode.quiz4.fundamentals;

import java.util.ArrayList;

/**
* @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;
Integer middle = str.length()/2;
return str.substring(0,middle) +
str.substring(middle, middle+1).toUpperCase() +
str.substring(middle+1);
}

public static String lowerCaseMiddleCharacter(String str) {
return null;
Integer middle = str.length()/2;
return str.substring(0,middle) +
str.substring(middle, middle+1).toLowerCase() +
str.substring(middle+1);
}

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

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

public static String removeConsecutiveDuplicateCharacters(String str) {
return null;
ArrayList<String> removed = new ArrayList<>();
for (int i = 0; i < str.length() - 1; i++) {
if(str.charAt(i) == str.charAt(i+1)) {
String remove = str.substring(i, i+2);
removed.add(remove);
}
}

String newString = str;
for (String s: removed) {
newString = newString.replace(s, "");
}

return newString;
}

public static String invertCasing(String str) {
return null;
StringBuilder newStr = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
if(Character.isUpperCase(str.charAt(i))) {
newStr.append(Character.toLowerCase(str.charAt(i)));
} else if(Character.isLowerCase(str.charAt(i))) {
newStr.append(Character.toUpperCase(str.charAt(i)));
} else {
newStr.append(str.charAt(i));
}
}

return newStr.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 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;

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

}
}
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;
}

public BankAccount(){
this.balance = 0.00;
}

@Override
public void deposit(Double amountToIncreaseBy) {
if (amountToIncreaseBy >= 0) setBalance(getBalance() + amountToIncreaseBy);
else throw new IllegalArgumentException();
}

@Override
public void withdrawal(Double amountToDecreaseBy) {
if (amountToDecreaseBy < 0 || amountToDecreaseBy > getBalance()) throw new IllegalArgumentException();
setBalance(getBalance() - amountToDecreaseBy);
}

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