Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.fundacionjala.coding.reinaldo.average;

import java.util.stream.IntStream;

/**
* Created by Administrator on 6/30/2017.
*
*/
public final class Average {
/**
* Constructor private.
*/
private Average() {

}

/**
* This method averagesCalculate verify is empty, null or only has
* one element or averges.
*
* @param sentence array.
* @return true if the array is not empty, null or has only one element.
*/
public static double[] averagesCalculate(final int[] sentence) {

return sentence == null || sentence.length < 2
? new double[0]
: IntStream.range(0, sentence.length - 1)
.mapToDouble(i -> (sentence[i] + sentence[i + 1]) / 2d).toArray();
}
}

43 changes: 43 additions & 0 deletions src/main/java/org/fundacionjala/coding/reinaldo/ean/Ean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.fundacionjala.coding.reinaldo.ean;

import java.util.stream.IntStream;


/**
* Created by Administrator on 6/30/2017.
*/
public final class Ean {

private static final int DIVISOR = 10;

/**
* This is the constructor of Ean.
*/
private Ean() {

}

/**
* @param eanCode validate checksum.
* @return boolean is checksum.
*/
static boolean validate(final String eanCode) {
final int sumToCheck = IntStream
.range(0, eanCode.length() - 1)
.reduce(0, (acc, index)
-> acc + Character.getNumericValue(eanCode.charAt(index)) * (1 + 2 * (index % 2)));

return Character.getNumericValue(eanCode.charAt(eanCode.length() - 1)) == getAnInt(sumToCheck);

}

/**
* This method return getAnInt.
*
* @param sumToCheck sumtocheck.
* @return int getSum
*/
private static int getAnInt(final int sumToCheck) {
return sumToCheck % DIVISOR == 0 ? 0 : DIVISOR - (sumToCheck % DIVISOR);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.fundacionjala.coding.reinaldo.evaporator;

/**
* Created by Administrator on 6/30/2017.
*
*/
final class Evaporator {

/**
* This is the constructor of Evaporator.
*/
private Evaporator() {

}

/**
* this method calc the Evaporator at day.
*
* @param cant is the cant
* @param lost is the lost
* @param limit is the limit
* @return int at day
*/
static int evaporator(final double cant, final double lost, final double limit) {
int result = 0;
do {
++result;
} while (Math.pow(1 - (lost / 100), result) > limit / 100);

return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.fundacionjala.coding.reinaldo.highestAndLowestTest;

import java.util.stream.Stream;

/**
* Created by Administrator on 6/30/2017.
*/
final class HighestAndLowest {
/**
* Private constructor.
*/
private HighestAndLowest() {
}

/**
* the method return the highAndLowest.
*
* @param numbers highAndLowest test
* @return String highAndLowest string
*/
static String highAndLowest(final String numbers) {


int high = Stream.of(numbers.split(" "))
.mapToInt(Integer::parseInt)
.max().getAsInt();

int low = Stream.of(numbers.split(" "))
.mapToInt(Integer::parseInt)
.min().getAsInt();

return String.format("%d %d", high, low);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package org.fundacionjala.coding.reinaldo.kataBankOcr;

import java.util.Arrays;
import java.util.List;

/**
* Created by reinaldo on 08/07/2017.
*/
final class BankOcrKata {
private static final int MODULUS_FACTOR = 11;
private static final int INCREMENT_BY_THREE = 3;
private static final int TAM_CHARACTERS = 26;

/**
* This is the constructor bankOcrKata.
*/
private BankOcrKata() {
}

/**
* This method decode a List<String>.
*
* @param listAccountNumber listAccount
* @return String list
*/
static String decode(final List<String> listAccountNumber) {
int charsPerCharacter = INCREMENT_BY_THREE;
int index = 0;
StringBuilder accountNumber = new StringBuilder();

while (index <= TAM_CHARACTERS) {

accountNumber.append(EncodedDigit.comparation(getDigitString(listAccountNumber, charsPerCharacter, index)));
charsPerCharacter += INCREMENT_BY_THREE;
index += INCREMENT_BY_THREE;

}

return accountNumber.toString();
}

/**
* This method return the a digite in strings for found on map.
*
* @param listAccountNumber listAccount
* @param charsPerCharacter charsper
* @param index index
* @return String string
*/
private static String getDigitString(final List<String> listAccountNumber,
final int charsPerCharacter, final int index) {
return String.format("%s%s%s",
listAccountNumber.get(0).substring(index, charsPerCharacter),
listAccountNumber.get(1).substring(index, charsPerCharacter),
listAccountNumber.get(2).substring(index, charsPerCharacter));
}


/**
* @param dateNamber parameter.
* @return ResultErrIll.
* this is my constructor 12/03/2017.
*/
static String codeCheck(final String dateNamber) {
return (dateNamber.matches("(.*)[?](.*)") ? "ILL" : (checkSumAcount(dateNamber) != 0) ? "ERR" : "OK");
}

/**
* @param accountNumber parameter.
* @return int.
*/
static int checkSumAcount(final String accountNumber) {

int multiplyByNine = 9;
List<String> listAcountNumber = Arrays.asList(accountNumber.split(""));
int suma = 0;

for (String wordItem : listAcountNumber) {
suma += Integer.parseInt(wordItem) * multiplyByNine--;
}

return suma % MODULUS_FACTOR;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.fundacionjala.coding.reinaldo.kataBankOcr;

/**
* Created by reinaldo on 12/03/2017.
*/
public enum Digit {
CERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.fundacionjala.coding.reinaldo.kataBankOcr;

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

/**
* Created by reinaldo on 08/07/2017.
*/
final class EncodedDigit {
private static final Map<Integer, String> MUMBER_MAP;

/**
* constructor.
*/
private EncodedDigit() {
}

/**
* method fill number digite.
*/
static {

MUMBER_MAP = new HashMap<Integer, String>();
MUMBER_MAP.put(Digit.CERO.ordinal(),
" _ "
+ "| |"
+ "|_|");
MUMBER_MAP.put(Digit.ONE.ordinal(),
" "
+ " |"
+ " |");
MUMBER_MAP.put(Digit.TWO.ordinal(),
" _ "
+ " _|"
+ "|_ ");
MUMBER_MAP.put(Digit.THREE.ordinal(),
" _ "
+ " _|"
+ " _|");
MUMBER_MAP.put(Digit.FOUR.ordinal(),
" "
+ "|_|"
+ " |");
MUMBER_MAP.put(Digit.FIVE.ordinal(),
" _ "
+ "|_ "
+ " _|");
MUMBER_MAP.put(Digit.SIX.ordinal(),
" _ "
+ "|_ "
+ "|_|");
MUMBER_MAP.put(Digit.SEVEN.ordinal(),
" _ "
+ " |"
+ " |");
MUMBER_MAP.put(Digit.EIGHT.ordinal(),
" _ "
+ "|_|"
+ "|_|");
MUMBER_MAP.put(Digit.NINE.ordinal(),
" _ "
+ "|_|"
+ " _|");
}

/**
* @param lineNumber this is string parameter.
* @return String.
*/
static String comparation(final String lineNumber) {
Iterator<Map.Entry<Integer, String>> it = MUMBER_MAP.entrySet().iterator();
String resulValue = "?";
while (it.hasNext()) {
Map.Entry<Integer, String> entry = it.next();
if (entry.getValue().equalsIgnoreCase(lineNumber)) {
return entry.getKey().toString();

}
}

return resulValue;
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.fundacionjala.coding.reinaldo.movies;

/**
* Created by Administrator on 3/21/2017.
*/
public class Children extends Movie {
private static final int LIMIT_NEW_CHILD = 3;
private static final double PRICE = 1.5;
private static final int NUMBER_RENTAL_DAYS = 1;

/**
* * This is the constructor of Children class.
*
* @param title title
*/
Children(final String title) {

super(title);
}

/**
* This is the calculateAmount of Children movie.
* {@inherentDoc}
*/
@Override
public double calculateAmount(final int daysRented) {
double amount = PRICE;
if (daysRented > LIMIT_NEW_CHILD) {
amount += (daysRented - LIMIT_NEW_CHILD) * PRICE;
}
return amount;
}

/**
* This is the calculateFrequentRenterPoints of Children movie.
* {@inherentDoc}
*/
@Override
public int calculateFrequentRenterPoints(final int daysRented) {
return NUMBER_RENTAL_DAYS;
}
}
Loading