From 535dc3c4b610cf8b04d3b92a9683f0a02e75be18 Mon Sep 17 00:00:00 2001 From: ushanil Date: Tue, 10 Dec 2019 05:18:05 -0500 Subject: [PATCH 1/6] 16 passed --- .../rocks/zipcode/quiz4/arrays/ArrayUtils.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/rocks/zipcode/quiz4/arrays/ArrayUtils.java b/src/main/java/rocks/zipcode/quiz4/arrays/ArrayUtils.java index 6deaf61..abb6c64 100644 --- a/src/main/java/rocks/zipcode/quiz4/arrays/ArrayUtils.java +++ b/src/main/java/rocks/zipcode/quiz4/arrays/ArrayUtils.java @@ -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 Date: Tue, 10 Dec 2019 05:42:46 -0500 Subject: [PATCH 2/6] 20 passed --- .../zipcode/quiz4/collections/WordCounter.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/rocks/zipcode/quiz4/collections/WordCounter.java b/src/main/java/rocks/zipcode/quiz4/collections/WordCounter.java index 2bf5ec2..903f221 100644 --- a/src/main/java/rocks/zipcode/quiz4/collections/WordCounter.java +++ b/src/main/java/rocks/zipcode/quiz4/collections/WordCounter.java @@ -1,12 +1,23 @@ package rocks.zipcode.quiz4.collections; -import java.util.Map; +import java.util.*; public class WordCounter { + private List words; public WordCounter(String... strings) { + words = Arrays.asList(strings); } + public WordCounter() { + words = new ArrayList<>(); + } + public Map getWordCountMap() { - return null; + + Map frequencyMap = new HashMap<>(); + for(String word : words) { + frequencyMap.put(word, Collections.frequency(words, word)); + } + return frequencyMap; } } From edfc3498e8e921e5f08c7b893d997e508179a0d8 Mon Sep 17 00:00:00 2001 From: ushanil Date: Tue, 10 Dec 2019 05:46:25 -0500 Subject: [PATCH 3/6] 55 passed --- .../quiz4/fundamentals/Calculator.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/rocks/zipcode/quiz4/fundamentals/Calculator.java b/src/main/java/rocks/zipcode/quiz4/fundamentals/Calculator.java index 02f2618..df022d6 100644 --- a/src/main/java/rocks/zipcode/quiz4/fundamentals/Calculator.java +++ b/src/main/java/rocks/zipcode/quiz4/fundamentals/Calculator.java @@ -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 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 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; } } From 3610c5cf1c9e3869b4b96f835362f4293cc7b1d9 Mon Sep 17 00:00:00 2001 From: ushanil Date: Tue, 10 Dec 2019 08:05:17 -0500 Subject: [PATCH 4/6] done arrays, collections and fundamentals --- .../quiz4/fundamentals/StringUtils.java | 68 +++++++++++++++++-- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/src/main/java/rocks/zipcode/quiz4/fundamentals/StringUtils.java b/src/main/java/rocks/zipcode/quiz4/fundamentals/StringUtils.java index 5ec61be..975b1b4 100644 --- a/src/main/java/rocks/zipcode/quiz4/fundamentals/StringUtils.java +++ b/src/main/java/rocks/zipcode/quiz4/fundamentals/StringUtils.java @@ -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 characterStream = str.chars() + .mapToObj(c -> (char) c); + List 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 characterStream = str.chars() + .mapToObj(c -> (char) c); + List 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; } } \ No newline at end of file From 7647351e0ccf1f58460c99a886a6e12368ecb20d Mon Sep 17 00:00:00 2001 From: ushanil Date: Tue, 10 Dec 2019 08:49:23 -0500 Subject: [PATCH 5/6] spice done --- .../quiz4/collections/culonary/Curry.java | 22 ++++++++++++++- .../quiz4/collections/culonary/Food.java | 28 +++++++++++++++++-- .../quiz4/collections/culonary/Ginger.java | 22 ++++++++++++++- .../quiz4/collections/culonary/Pepper.java | 17 ++++++++++- .../quiz4/collections/culonary/Spice.java | 1 + 5 files changed, 84 insertions(+), 6 deletions(-) diff --git a/src/main/java/rocks/zipcode/quiz4/collections/culonary/Curry.java b/src/main/java/rocks/zipcode/quiz4/collections/culonary/Curry.java index 199cefc..9eb760f 100644 --- a/src/main/java/rocks/zipcode/quiz4/collections/culonary/Curry.java +++ b/src/main/java/rocks/zipcode/quiz4/collections/culonary/Curry.java @@ -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); + } } diff --git a/src/main/java/rocks/zipcode/quiz4/collections/culonary/Food.java b/src/main/java/rocks/zipcode/quiz4/collections/culonary/Food.java index e06abbc..2651fff 100644 --- a/src/main/java/rocks/zipcode/quiz4/collections/culonary/Food.java +++ b/src/main/java/rocks/zipcode/quiz4/collections/culonary/Food.java @@ -1,5 +1,7 @@ package rocks.zipcode.quiz4.collections.culonary; +import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -7,14 +9,34 @@ * @author leon on 27/12/2018. */ public class Food { + Map, Integer> spiceMap; + List spices; + + public Food(){ + this(null); + } + + public Food(Map, Integer> spiceMap) { + if(spiceMap != null) + this.spiceMap = spiceMap; + else + this.spiceMap = new LinkedHashMap<>(); + spices = new ArrayList<>(); + } + public List getAllSpices() { - return null; + return spices; } - public > Map getSpiceCount() { - return null; + public > Map, Integer> getSpiceCount() { + //public > Map 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); } } diff --git a/src/main/java/rocks/zipcode/quiz4/collections/culonary/Ginger.java b/src/main/java/rocks/zipcode/quiz4/collections/culonary/Ginger.java index 3c4e177..c150700 100644 --- a/src/main/java/rocks/zipcode/quiz4/collections/culonary/Ginger.java +++ b/src/main/java/rocks/zipcode/quiz4/collections/culonary/Ginger.java @@ -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); + } } diff --git a/src/main/java/rocks/zipcode/quiz4/collections/culonary/Pepper.java b/src/main/java/rocks/zipcode/quiz4/collections/culonary/Pepper.java index 4b771a8..bdc0e39 100644 --- a/src/main/java/rocks/zipcode/quiz4/collections/culonary/Pepper.java +++ b/src/main/java/rocks/zipcode/quiz4/collections/culonary/Pepper.java @@ -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); + } } diff --git a/src/main/java/rocks/zipcode/quiz4/collections/culonary/Spice.java b/src/main/java/rocks/zipcode/quiz4/collections/culonary/Spice.java index 9ab865b..ed6e324 100644 --- a/src/main/java/rocks/zipcode/quiz4/collections/culonary/Spice.java +++ b/src/main/java/rocks/zipcode/quiz4/collections/culonary/Spice.java @@ -4,4 +4,5 @@ * @author leon on 27/12/2018. */ public interface Spice { + public String getName(); } From 27d7c02b86f2281c715b0e23793cca9d12da47ee Mon Sep 17 00:00:00 2001 From: ushanil Date: Tue, 10 Dec 2019 09:03:47 -0500 Subject: [PATCH 6/6] All done --- .../objectorientation/account/Account.java | 6 ++- .../quiz4/objectorientation/account/Bank.java | 16 ++++-- .../account/BankAccount.java | 28 +++++++++- .../objectorientation/account/Employee.java | 51 ++++++++++++++++++- 4 files changed, 93 insertions(+), 8 deletions(-) diff --git a/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Account.java b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Account.java index 40eb4a8..574ba32 100644 --- a/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Account.java +++ b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Account.java @@ -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; } } diff --git a/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Bank.java b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Bank.java index 0dd4183..b851951 100644 --- a/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Bank.java +++ b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Bank.java @@ -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 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); } } diff --git a/src/main/java/rocks/zipcode/quiz4/objectorientation/account/BankAccount.java b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/BankAccount.java index 70ccb74..51f98c1 100644 --- a/src/main/java/rocks/zipcode/quiz4/objectorientation/account/BankAccount.java +++ b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/BankAccount.java @@ -3,7 +3,33 @@ /** * @author leon on 27/12/2018. */ -public class BankAccount { +public class BankAccount extends Account implements Transactable { + private Double balance; + + public BankAccount() { + this.balance = 0.00; + } + public void setBalance(Double val) { + this.balance = val; + } + + @Override + public void deposit(Double amountToIncreaseBy) { + if (amountToIncreaseBy < 0) throw new IllegalArgumentException(); + else this.setBalance(this.getBalance()+amountToIncreaseBy); + } + + @Override + public void withdrawal(Double amountToDecreaseBy) { + if (amountToDecreaseBy < 0 || this.getBalance() < amountToDecreaseBy) + throw new IllegalArgumentException(); + else + this.setBalance(this.getBalance()-amountToDecreaseBy); + } + + @Override + public Double getBalance() { + return this.balance; } } diff --git a/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Employee.java b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Employee.java index 8407f1a..fcb8772 100644 --- a/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Employee.java +++ b/src/main/java/rocks/zipcode/quiz4/objectorientation/account/Employee.java @@ -3,18 +3,65 @@ /** * @author leon on 30/12/2018. */ -public class Employee { +public class Employee implements Worker, Transactable{ + private Double hoursWorked; + private Double hourlyWage; + private BankAccount bankAccount; + public Employee() { + this.hoursWorked = 0.00; + this.hourlyWage = 35.00; + this.bankAccount = new BankAccount(); } public Employee(BankAccount bankAccount) { + this.hoursWorked = 0.00; + this.hourlyWage = 35.00; + this.bankAccount = bankAccount; } public BankAccount getBankAccount() { - return null; + return this.bankAccount; } public void setBankAccount(BankAccount bankAccount) { + this.bankAccount = bankAccount; + + } + + @Override + public void deposit(Double amountToIncreaseBy) { + this.bankAccount.deposit(amountToIncreaseBy); + + } + + @Override + public void withdrawal(Double amountToDecreaseBy) { + this.bankAccount.withdrawal(amountToDecreaseBy); + } + + @Override + public Double getBalance() { + return this.bankAccount.getBalance(); + } + + @Override + public void increaseHoursWorked(Double numberOfHours) { + this.hoursWorked += numberOfHours; + } + + @Override + public Double getHoursWorked() { + return this.hoursWorked; + } + + @Override + public Double getHourlyWage() { + return this.hourlyWage; + } + @Override + public Double getMoneyEarned() { + return this.hoursWorked * this.hourlyWage; } }