From 96879f7c1a8bf9a1b723fe2634b3298f3b14e254 Mon Sep 17 00:00:00 2001 From: ruppal Date: Fri, 20 Mar 2020 18:11:22 -0400 Subject: [PATCH 1/2] 1 test not passing --- .../zipcode/quiz4/arrays/ArrayUtils.java | 24 +++++-- .../quiz4/collections/WordCounter.java | 16 ++++- .../quiz4/collections/culonary/Curry.java | 2 +- .../quiz4/collections/culonary/Food.java | 17 ++++- .../quiz4/collections/culonary/Ginger.java | 2 +- .../quiz4/collections/culonary/Pepper.java | 2 +- .../quiz4/fundamentals/Calculator.java | 21 +++--- .../quiz4/fundamentals/StringUtils.java | 68 ++++++++++++++++--- .../objectorientation/account/Account.java | 7 +- .../quiz4/objectorientation/account/Bank.java | 19 +++++- .../account/BankAccount.java | 36 +++++++++- .../objectorientation/account/Employee.java | 52 +++++++++++++- 12 files changed, 229 insertions(+), 37 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..d0147d6 100644 --- a/src/main/java/rocks/zipcode/quiz4/arrays/ArrayUtils.java +++ b/src/main/java/rocks/zipcode/quiz4/arrays/ArrayUtils.java @@ -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 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 getWordCountMap() { - return null; + return result; } } 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..c6b96b4 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,4 @@ package rocks.zipcode.quiz4.collections.culonary; -public class Curry { +public class Curry implements Spice { } 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..4773ea4 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.HashMap; import java.util.List; import java.util.Map; @@ -7,14 +9,25 @@ * @author leon on 27/12/2018. */ public class Food { + ArrayList spices = new ArrayList<>(); + + public List getAllSpices() { - return null; + return spices; } public > Map getSpiceCount() { - return null; + + HashMap 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); } } 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..ef695be 100644 --- a/src/main/java/rocks/zipcode/quiz4/collections/culonary/Ginger.java +++ b/src/main/java/rocks/zipcode/quiz4/collections/culonary/Ginger.java @@ -3,5 +3,5 @@ /** * @author leon on 27/12/2018. */ -public class Ginger { +public class Ginger implements Spice{ } 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..248859f 100644 --- a/src/main/java/rocks/zipcode/quiz4/collections/culonary/Pepper.java +++ b/src/main/java/rocks/zipcode/quiz4/collections/culonary/Pepper.java @@ -3,5 +3,5 @@ /** * @author leon on 27/12/2018. */ -public class Pepper { +public class Pepper implements Spice{ } diff --git a/src/main/java/rocks/zipcode/quiz4/fundamentals/Calculator.java b/src/main/java/rocks/zipcode/quiz4/fundamentals/Calculator.java index 02f2618..251063f 100644 --- a/src/main/java/rocks/zipcode/quiz4/fundamentals/Calculator.java +++ b/src/main/java/rocks/zipcode/quiz4/fundamentals/Calculator.java @@ -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 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); } } 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..109a667 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,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; } } 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..86aa1a3 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,66 @@ /** * @author leon on 30/12/2018. */ -public class Employee { +public class Employee implements Worker, Transactable { + private BankAccount bankAccount; + private Double hourlyWage; + private Double hoursWorked; + + public Employee() { + this.bankAccount = new BankAccount(); + this.hourlyWage = 35.0; + this.hoursWorked = 0.0; } public Employee(BankAccount bankAccount) { + this.bankAccount = bankAccount; + this.hourlyWage = 35.0; + this.hoursWorked = 0.0; } public BankAccount getBankAccount() { - return null; + return this.bankAccount; } public void setBankAccount(BankAccount bankAccount) { + this.bankAccount = bankAccount; + } + + @Override + public void deposit(Double amountToIncreaseBy) { + this.bankAccount.setBalance(getBalance()+amountToIncreaseBy); + + } + + @Override + public void withdrawal(Double amountToDecreaseBy) { + + } + @Override + public Double getBalance() { + return this.bankAccount.getBalance(); + } + + @Override + public void increaseHoursWorked(Double numberOfHours) { + hoursWorked += numberOfHours; + + } + + @Override + public Double getHoursWorked() { + return hoursWorked; + } + + @Override + public Double getHourlyWage() { + return hourlyWage; + } + + @Override + public Double getMoneyEarned() { + return null; } } From 4d1eb2f2e799938e53a49d1c9d6c05aa116036f5 Mon Sep 17 00:00:00 2001 From: ruppal Date: Sat, 9 May 2020 14:09:41 -0400 Subject: [PATCH 2/2] redid --- src/main/java/rocks/zipcode/quiz4/fundamentals/StringUtils.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/rocks/zipcode/quiz4/fundamentals/StringUtils.java b/src/main/java/rocks/zipcode/quiz4/fundamentals/StringUtils.java index fcc01d1..09beff4 100644 --- a/src/main/java/rocks/zipcode/quiz4/fundamentals/StringUtils.java +++ b/src/main/java/rocks/zipcode/quiz4/fundamentals/StringUtils.java @@ -77,4 +77,6 @@ else if (Character.isLowerCase(c)) } return new String(chars); } + + } \ No newline at end of file