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

Done. Quiz4. #73

Open
wants to merge 3 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
19 changes: 15 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,33 @@
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[] result = new String[values.length-1];
int count = 0;
for (int i = 0; i < values.length; i++) {
if(!values[i].equals(getMiddleElement(values))){
result[count] = values[i];
count++;
}
}
return result;
}

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

public static String[] removeLastElement(String[] values) {
return null;
return Arrays.copyOf(values,values.length-1);
}
}
13 changes: 12 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,23 @@
package rocks.zipcode.quiz4.collections;

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

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

public WordCounter(String... strings) {
for (String x : strings) {
Integer count = 1;
if (myMap.containsKey(x)) {
count = myMap.get(x);
count++;
}
myMap.put(x, count);
}
}

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

public class Curry {
import sun.security.provider.ConfigFile;

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

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

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

for(Spice s: spices){
Integer count = 1;
if(result.containsKey((SpiceType) s.getClass())){
count = result.get((SpiceType) s.getClass());
count++;
}
result.put((SpiceType) s.getClass(), count);
}
return result;
}

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
@@ -1,7 +1,9 @@
package rocks.zipcode.quiz4.collections.culonary;

import sun.security.provider.ConfigFile;

/**
* @author leon on 27/12/2018.
*/
public class Pepper {
public class Pepper implements Spice {
}
27 changes: 19 additions & 8 deletions src/main/java/rocks/zipcode/quiz4/fundamentals/Calculator.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
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;
}
}
48 changes: 41 additions & 7 deletions src/main/java/rocks/zipcode/quiz4/fundamentals/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,64 @@
*/
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;

return str.substring(0,str.length()/2) + getMiddleCharacter(str.toUpperCase()) + str.substring((str.length()/2)+1);
}

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

return str.substring(0,str.length()/2) + getMiddleCharacter(str.toLowerCase()) + str.substring((str.length()/2)+1);
}

public static Boolean isIsogram(String str) {
return null;

char[] element = str.toCharArray();
for(int i = 0; i < element.length; i++){
for (int j = i+1; j < element.length;j++){
if (element[i] == element[j]){
return false;
}
}
}
return true;
}

public static Boolean hasDuplicateConsecutiveCharacters(String str) {
return null;

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

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

for(int i = 0; i < str.length()-1; i++){
if (str.charAt(i) == str.charAt(i+1)){
str = str.substring(0,i)+ str.substring(i+2);
}
}
return str;
}

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

char[] element = str.toCharArray();
for(int i = 0; i < element.length; i++) {
if(Character.isLowerCase(element[i])) {
element[i] = Character.toUpperCase(element[i]);
}
else {
element[i] = Character.toLowerCase(element[i]);
}
}
return String.valueOf(element);
}
}
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{
Long id;

public Long getId() {
return null;
return id;
}

public void setId(Long id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
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 = new ArrayList<>();

public BankAccount removeBankAccountByIndex(Integer indexNumber) {
return null;

return accounts.remove(indexNumber.intValue());
}

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,27 @@
/**
* @author leon on 27/12/2018.
*/
public class BankAccount {
public class BankAccount extends Account implements Transactable {
Double balance = 0.0;

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

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

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

@Override
public Double getBalance() {
return balance;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,59 @@
/**
* @author leon on 30/12/2018.
*/
public class Employee {
public class Employee implements Worker, Transactable {
private BankAccount account;
private Double hourlyWage = 35.0;
private Double hoursWorked = 0.0;

public Employee() {
account = new BankAccount();
}

public Employee(BankAccount bankAccount) {
account = bankAccount;
}

public BankAccount getBankAccount() {
return null;
return account;
}

public void setBankAccount(BankAccount bankAccount) {
account = bankAccount;
}

@Override
public void deposit(Double amountToIncreaseBy) {
account.deposit(amountToIncreaseBy);
}

@Override
public void withdrawal(Double amountToDecreaseBy) {
account.withdrawal(amountToDecreaseBy);
}

@Override
public Double getBalance() {
return account.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 hoursWorked * hourlyWage;
}
}