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
30 changes: 30 additions & 0 deletions src/main/java/org/fundacionjala/coding/norman/average/Average.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.fundacionjala.coding.norman.average;

import java.util.stream.IntStream;

/**
* Created by NORMAN on 2/7/2017.
*/
public final class Average {
/**
* Contructor.
*/
private Average() {

}

/**
* average to array.
*
* @param numbers array.
* @return array.
*/

public static double[] averages(final int[] numbers) {
return (numbers == null || numbers.length <= 1)
? new double[]{}
: IntStream.range(0, numbers.length - 1)
.mapToDouble(i -> (numbers[i] + numbers[i + 1]) / 2.0)
.toArray();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.fundacionjala.coding.norman.banck_ocr;

/**
* Created by NORMAN on 2/7/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,84 @@
package org.fundacionjala.coding.norman.banck_ocr;

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

/**
* Created by NORMAN on 2/7/2017.
*/
public class FileNumberBankOcr {
private Map<Integer, String> numberMap;

/**
* constructor.
*/
FileNumberBankOcr() {
numberMap = new HashMap<Integer, String>();
fillNumber();

}

/**
* method fill number digite.
*/
public void fillNumber() {
Copy link
Contributor

@carledriss carledriss Jul 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@666nonak666
Instead of having this method
you can have a static attribute.
Review again

numberMap.put(Digit.CERO.ordinal(),
" _ "
+ "| |"
+ "|_|");
numberMap.put(Digit.ONE.ordinal(),
" |"
+ " |"
+ " |");
numberMap.put(Digit.TWO.ordinal(),
" _ "
+ " _|"
+ "|_ ");
numberMap.put(Digit.THREE.ordinal(),
"__ "
+ " _|"
+ "__|");
numberMap.put(Digit.FOUR.ordinal(),
" "
+ "|_|"
+ " |");
numberMap.put(Digit.FIVE.ordinal(),
" __"
+ "|__"
+ " __|");
numberMap.put(Digit.SIX.ordinal(),
" __"
+ "|__"
+ "|__|");
numberMap.put(Digit.SEVEN.ordinal(),
"__ "
+ " |"
+ " |");
numberMap.put(Digit.EIGHT.ordinal(),
" _ "
+ "|_|"
+ "|_|");
numberMap.put(Digit.NINE.ordinal(),
" _ "
+ "|_|"
+ " _|");
}

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

return resulValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.fundacionjala.coding.norman.banck_ocr;

import java.util.List;

/**
* Created by NORMAN on 2/7/2017.
*/
public class HistoryOneBankOcr extends FileNumberBankOcr {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AT-03/at-03
We don't here inheritance
Please have a single class for BankOCR

/**
* This is my constructor BankOCR.
*/
public HistoryOneBankOcr() {
super();

}

/**
* @param lines this is mi data insert lines.
* @return String return string in format digit.
* change y
*/
public String verificationLineNumber(final List<String> lines) {
StringBuilder resulta = new StringBuilder();
for (String line : lines) {
resulta.append(super.comparation(line));
}
return resulta.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.fundacionjala.coding.norman.banck_ocr;

/**
* Created by NORMAN on 2/7/2017.
*/
public class HistoryThreeErrFall extends HistoryTwoChecksum {

/**
* this is my constructor 12/03/2017.
*/
public HistoryThreeErrFall() {
super();
}

/**
* @param dateNamber parameter.
* @return ResultErrIll.
* this is my constructor 12/03/2017.
*/
public String verificateNumber(final String dateNamber) {
return (dateNamber.matches("(.*)[?](.*)") ? "ILL" : (checkSumAcount(dateNamber) != 0) ? "ERR" : "OK");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.fundacionjala.coding.norman.banck_ocr;

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

/**
* Created by NORMAN on 2/7/2017.
*/
public class HistoryTwoChecksum extends FileNumberBankOcr {

private int multiplyByNine = 9;
private static final int MODULUS_FACTOR = 11;

/**
* HistoryTwoChecksum.
*/
public HistoryTwoChecksum() {
super();
}

/**
* @param accountNumber parameter.
* @return int.
*/
public int checkSumAcount(final String accountNumber) {
List<String> listaCadena = Arrays.asList(accountNumber.split(""));
int suma = 0;
for (String dato : listaCadena) {
suma += Integer.parseInt(dato) * multiplyByNine--;
}
return suma % MODULUS_FACTOR;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.fundacionjala.coding.norman.eanvalidator;

/**
* Created by NORMAN on 2/7/2017.
*/
public final class EANValidator {
private static final int ODD_DIGIT_MULTIPLIER = 3;
private static final int DIVISIBILITY_FACTOR = 10;

/**
* Constructor private.
*/

private EANValidator() {
}

/**
* Takes an string number to verify it is checksum it's correct.
*
* @param eAN String number with exactly 13 digits.
* @return true if the checksum is ok.
*/

static boolean validate(final String eAN) {
int sum = 0;


for (int i = 1; i < eAN.length(); i++) {
int numericValue = Character.getNumericValue(eAN.charAt(i - 1));
sum += i % 2 == 0 ? numericValue * ODD_DIGIT_MULTIPLIER : numericValue;
}

int module = sum % DIVISIBILITY_FACTOR;
int check = module != 0 ? DIVISIBILITY_FACTOR - module : 0;

return check == Character.getNumericValue(eAN.charAt(eAN.length() - 1));

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.fundacionjala.coding.norman.evaporator;

/**
* Created by NORMAN on 2/7/2017.
*/
public final class Evaporator {

private static final int INT = 100;

/**
* Contructor.
*/
private Evaporator() {

}

/**
* method calculate time in days when evaporate the liquid.
*
* @param cant cant of liquid.
* @param porcentaje porcentage evaporation.
* @param umbral limit the evaporation in porcentage.
* @return cant days.
*/
public static int evaporator(final double cant, final double porcentaje, final double umbral) {
int res = 0;
double aux = INT;
while (aux > umbral) {
aux -= porcentaje * aux / INT;
res++;
}
return res;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.fundacionjala.coding.norman.highestandlowest;

import java.util.Arrays;
import java.util.stream.Stream;

/**
* Created by NORMAN on 2/7/2017.
*/
public final class HighestAndLowest {
/**
* Private constructor.
*/
private HighestAndLowest() {
}

/**
* The method return the highest and lowest value of a number array.
*
* @param numbers is the String of numbers.
* @return a String with the highest and lowest values.
*/
static String highAndLowest(final String numbers) {


int[] digits = Stream.of(numbers.split(" ")).mapToInt(Integer::parseInt).toArray();
Arrays.sort(digits);

return String.format("%d %d", digits[digits.length - 1], digits[0]);
}
}
32 changes: 32 additions & 0 deletions src/main/java/org/fundacionjala/coding/norman/movies/Children.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.fundacionjala.coding.norman.movies;

/**
* Created by NORMAN on 2/7/2017.
*/
public class Children extends Movie {
private static final int LIMIT_DAYS_TO_RENT_CHILDREN_MOVIE = 3;
private static final double NO_RELEASE_MOVIE_FEE = 1.5;

/**
* Children constructor.
*
* @param title of String type.
*/
Children(final String title) {
super(title);
}

@Override
public double calculateAmount(final int daysRented) {
double amount = NO_RELEASE_MOVIE_FEE;
if (daysRented > LIMIT_DAYS_TO_RENT_CHILDREN_MOVIE) {
amount += (daysRented - LIMIT_DAYS_TO_RENT_CHILDREN_MOVIE) * NO_RELEASE_MOVIE_FEE;
}
return amount;
}

@Override
public int calculateFrequentRenterPoints(final int daysRented) {
return 1;
}
}
Loading