Skip to content

Exercises completed #25

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

Open
wants to merge 28 commits into
base: develop
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.fundacionjala.coding.Fernando.StringInv;

/**
* Write a description of class StringInv here.
*
* @author (your name)
* @version (a version number or a date)
*/
public final class StringInv {

static final int MAJOR_FIVE_LETTERS = 5;

/**
* Constructor StringInv.
*/
private StringInv() {
}

/**
* @param text param.
* @return String param.
*/
public static String stringInv(final String text) {
int pos = 0;
String[] parts = text.split(" ");
while (pos < parts.length) {
if (parts[pos].length() > MAJOR_FIVE_LETTERS) {
parts[pos] = new StringBuilder(parts[pos]).reverse().toString();
}
pos++;
}
return String.join(" ", parts);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.fundacionjala.coding.Fernando.average;

/**
* Write a description of class Average here.
*
* @author (your name)
* @version (a version number or a date)
*/
public final class Average {

/**
* Constructor Average.
*/
private Average() {
}

/**
* @param num the method has a int value.
* @return double value.
*/
public static double[] average(final int[] num) {
double[] res = {};
if (num != null && num.length != 0) {
return average(num, 0);
}
return res;
}

/**
* @param num the method has a int value.
* @param pos1 param.
* @return double value.
*/
private static double[] average(final int[] num, final int pos1) {
double[] res = new double[num.length - 1];
for (int pos = 0; pos < num.length - 1; pos++) {
double prom = (double) (num[pos] + num[pos + 1]) / 2;
res[pos] = prom;
}
return res;

}
}
142 changes: 142 additions & 0 deletions src/main/java/org/fundacionjala/coding/Fernando/bankOCR/BankOCR.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package org.fundacionjala.coding.Fernando.bankOCR;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;

/**
* Created by PC on 24/06/2017.
*/
public final class BankOCR {

private static final int ZERO = 0;
private static final int ONE = 1;
private static final int TWO = 2;
private static final int THREE = 3;
private static final int FOUR = 4;
private static final int FIVE = 5;
private static final int SIX = 6;
private static final int SEVEN = 7;
private static final int EIGHT = 8;
private static final int NINE = 9;
private static final Map<Integer, String> MAP = new HashMap<>();
static final int VALIDATOR = 11;

static {
MAP.put(ZERO,
" _ "
+ "| |"
+ "|_|");
MAP.put(ONE,
" "
+ " |"
+ " |");
MAP.put(TWO,
" _ "
+ " _|"
+ "|_ ");
MAP.put(THREE,
"__ "
+ " _|"
+ "__|");
MAP.put(FOUR,
" "
+ "|_|"
+ " |");
MAP.put(FIVE,
" _ "
+ "|_ "
+ " _|");
MAP.put(SIX,
" _ "
+ "|_ "
+ "|_|");
MAP.put(SEVEN,
"__ "
+ " |"
+ " |");
MAP.put(EIGHT,
" _ "
+ "|_|"
+ "|_|");
MAP.put(NINE,
" _ "
+ "|_|"
+ " _|");
}

/**
* Constructor bankOCR.
*/
private BankOCR() {

}

/**
* @param value of string numbers.
* @return String of value number.
*/
private static String getMapKey(final String value) {
String res = "?";
for (Map.Entry<Integer, String> entry : MAP.entrySet()) {
if (entry.getValue().equals(value)) {
res = entry.getKey().toString();
}
}
return res;
}

/**
* @param cad value of string numbers.
* @return String to get the all numbers.
*/
public static String parseDigit(final String[] cad) {
String res = "";
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this variable?

StringBuilder value = new StringBuilder();
for (String data : cad) {
res = value.append(getMapKey(data)).toString();
}

return res;
}

/**
* @param cad value of string numbers.
* @return String to get the ERR o ILL error result.
*/
public static String accountStatus(final String cad) {
String res = "";
if (!digit(cad)) {
res = "ILL";
} else if (!validAccountNumbers(cad)) {
res = "ERR";
}
return res;
}

/**
* @param data value of string numbers.
* @return boolean to get if is a valid digit.
*/
private static boolean digit(final String data) {
return Stream.of(data.split("")).
filter(a -> Character.isDigit(a.charAt(0))).count() > 0;
}

/**
* @param input String value.
* @return boolean valor if is valid account number.
*/
public static boolean validAccountNumbers(final String input) {
int suma = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

typo
suma?

for (int i = input.length() - 1; i >= 0; i--) {
int multiplier = 1;
int x = (int) (input.charAt(i)) * multiplier;
suma += x;
multiplier++;
}
return suma % VALIDATOR == 0;
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.fundacionjala.coding.Fernando.checkSum;

/**
* Write a description of class checkSum here.
*
* @author (your name)
* @version (a version number or a date)
*/
public final class CheckSum {
static final int THREE = 3;
static final int ONE = 1;
static final int TEN = 10;
static final int TWO = 2;
static final int EIGHT = 8;
static final int ZERO = 0;
static final int SIZEVALUE = 13;

/**
* Constructor checksum.
*/
private CheckSum() {

}

/**
* @param value data.
* @return boolean of cant values.
*/
public static boolean canValues(final String value) {
int sum = ZERO;
if (value.length() != SIZEVALUE) {
return false;
}
for (int i = ONE; i < value.length(); i++) {
int num = Character.getNumericValue(value.charAt(i - 1));
sum += i % 2 == 0 ? num * THREE : num;
}
return validNum(sum) == Character.getNumericValue(value.charAt(value.length() - 1));
}

/**
* @param sum of values.
* @return int of number valid.
*/
public static int validNum(final int sum) {
int result = sum % TEN;
return result != 0 ? TEN - result : 0;

}

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

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

private static final int PERCENTAGE_TOTAL = 100;

/**
* Constructor evaporator kata.
*/
private Evaporator() {
}

/**
* @param content content containing.
* @param evapPerDay evaporation day.
* @param limit limit.
* @return life of an evaporator containing gas.
*/

public static int evaporator(final double content, final double evapPerDay, final double limit) {
int res = 0;
double reduceConten = content;
double limitContent = content * limit / PERCENTAGE_TOTAL;
while (reduceConten >= limitContent) {
reduceConten = reduceConten - (reduceConten * evapPerDay / PERCENTAGE_TOTAL);
res++;
}
return res;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.fundacionjala.coding.Fernando.haghestandlowest;

/**
* Created by PC on 24/06/2017.
*/
public final class HighAndLow {

/**
* Method constructor.
*/
private HighAndLow() {
}

/**
* This method get the high and low number.
*
* @param numbers to get the high and low number.
* @return String method.
*/
static String highAndLowest(final String numbers) {
String[] value = numbers.split(" ");
int majorNumber = Integer.parseInt(value[0]);
int minorNumber = majorNumber;
for (String res : value) {
int num = Integer.parseInt(res);
if (num > majorNumber) {
majorNumber = Integer.parseInt(res);
}
if (num < minorNumber) {
minorNumber = Integer.parseInt(res);
}
}

return String.format("%d %d", majorNumber, minorNumber);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.fundacionjala.coding.Fernando.movies;

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

/**
* @param title param.
*/
public Children(final String title) {
super(title);
}

/**
* @param daysRented param.
* @return double value.
*/
@Override
public double calculateAmount(final int daysRented) {
double amount = PRICE;
if (daysRented > LIMITNEWCHILD) {
amount += (daysRented - LIMITNEWCHILD) * PRICE;
}
return amount;
}

/**
* @param daysRented param.
* @return int value.
*/
@Override
public int calculateFrequentRenterPoints(final int daysRented) {
return RENT_ONE_DAY;
}
}
Loading