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

1 test not passing #58

Open
wants to merge 2 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
24 changes: 20 additions & 4 deletions src/main/java/rocks/zipcode/quiz4/arrays/ArrayUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,34 @@
*/
public class ArrayUtils {
public static String getMiddleElement(String[] values) {
return null;
return values[values.length/2];
}

public static String[] removeMiddleElement(String[] values) {
return null;
Integer cnt = 0;
String[] result = new String[values.length-1];
values[values.length/2] = null;
for (int i = 0; i <values.length ; i++) {
if (values[i] != null){
result[cnt]=values[i];
cnt++;
}
}
return result;
}

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];
values[values.length-1] = null;
for (int i = 0; i <values.length ; i++) {
if (values[i] != null){
result[i]=values[i];
}
}
return result;
}
}
16 changes: 15 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,26 @@
package rocks.zipcode.quiz4.collections;

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

public class WordCounter {
HashMap<String,Integer> result = new HashMap<>();

public WordCounter(String... strings) {
for (String item : strings){
if(result.containsKey(item)){

Integer count = result.get(item);
result.put(item,count+1);

}else{
result.put(item,1);
}
}
}

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

public class Curry {
public class Curry implements Spice {
}
17 changes: 15 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,33 @@
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 {
ArrayList<Spice> spices = new ArrayList<>();


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

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

HashMap<SpiceType,Integer> spiceCountMap = new HashMap<>();
SpiceType spice = (SpiceType) this.spices.get(0).getClass();
Integer spiceCount = this.spices.size();
spiceCountMap.put(spice,spiceCount);


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,5 @@
/**
* @author leon on 27/12/2018.
*/
public class Ginger {
public class Ginger implements Spice{
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
/**
* @author leon on 27/12/2018.
*/
public class Pepper {
public class Pepper implements Spice{
}
21 changes: 13 additions & 8 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,36 @@
*/
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;
for (int i = 0; i <value.length ; i++) {
value[i] = Math.sqrt(value[i]);
}
return value;
}

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

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; }
}
70 changes: 59 additions & 11 deletions src/main/java/rocks/zipcode/quiz4/fundamentals/StringUtils.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,82 @@
package rocks.zipcode.quiz4.fundamentals;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

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

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

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

public static Boolean isIsogram(String str) {
return null;
}
char arr[] = str.toCharArray();

Arrays.sort(arr);
for (int i = 0; i < str.length() - 1; i++) {
if (arr[i] == arr[i + 1])
return false;
}
return true;
}

public static Boolean hasDuplicateConsecutiveCharacters(String str) {
return null;
char arr[] = str.toCharArray();


for (int i = 0; i < str.length() - 1; i++) {
if (arr[i] == arr[i + 1])
return true;
}
return false;
}

public static String removeConsecutiveDuplicateCharacters(String str) {
return null;
}
StringBuilder stringBuilder = new StringBuilder(str);
for(int i = 1; i <= str.length()-1; i++){
if(str.charAt(i) == str.charAt(i-1)) {
stringBuilder.replace(i - 1, i + 1, "");
}
}
return stringBuilder.toString();

public static String invertCasing(String str) {
return null;
}


public static String invertCasing(String str) {
char[] chars = str.toCharArray();
for (int i = 0; i < chars.length; i++)
{
char c = chars[i];
if (Character.isUpperCase(c))
{
chars[i] = Character.toLowerCase(c);
}
else if (Character.isLowerCase(c))
{
chars[i] = Character.toUpperCase(c);
}
}
return new String(chars);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
/**
* @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,30 @@
package rocks.zipcode.quiz4.objectorientation.account;

import java.util.ArrayList;

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

public Boolean removeBankAccountByIndex(Integer indexNumber) {
BankAccount temp = null;

if (accounts.size() > 0 && indexNumber <= accounts.size()){
temp = accounts.get(indexNumber);
accounts.remove(temp);

}
return containsBankAccount(temp);
}

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

}

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

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

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

@Override
public void deposit(Double amountToIncreaseBy) {

if (amountToIncreaseBy < 0.0){
throw new IllegalArgumentException();
}else{
balance += amountToIncreaseBy;

}
}

@Override
public void withdrawal(Double amountToDecreaseBy) {
if (amountToDecreaseBy < 0.0 || amountToDecreaseBy > balance) {
throw new IllegalArgumentException();

}else{
balance -= amountToDecreaseBy;
}

}

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