Skip to content

Feature/all katas #19

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 48 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
7d86ee0
commit1
jpaitken Mar 10, 2017
772d31e
commit2 with gradle check
jpaitken Mar 19, 2017
431fc30
Delete bank_Machinne.java
jpaitken Mar 19, 2017
0770a7a
Update EanValidator.java
jpaitken Mar 19, 2017
667db53
commit3
jpaitken Mar 19, 2017
175b1fd
commit MOVIES
jpaitken Mar 26, 2017
ebd41d3
commit 26/3
jpaitken Mar 26, 2017
93f81bf
Commit Test
jpaitken Mar 26, 2017
4081f11
BankCommit - firts
jpaitken Mar 26, 2017
3800786
katas
jpaitken Jun 19, 2017
4349bce
All Katas
jpaitken Jun 28, 2017
d6953c2
Merge branch 'develop' into feature/allKatas
jpaitken Jun 28, 2017
268d209
All Katas
jpaitken Jun 28, 2017
dae303b
Merge remote-tracking branch 'origin/feature/allKatas' into feature/a…
jpaitken Jun 28, 2017
7670dc4
Merge branch 'develop' of https://github.com/AT-03/coding into featur…
jpaitken Jul 1, 2017
6e0be4e
Code improved
jpaitken Jul 1, 2017
19a464d
Code improved
jpaitken Jul 2, 2017
9896805
ternary condition on EanValidator
jpaitken Jul 3, 2017
baccd7e
Test refactored
jpaitken Jul 3, 2017
ead8057
SpinWords refactored.
jpaitken Jul 3, 2017
04abfb4
New coverage.
jpaitken Jul 3, 2017
244b99a
Banck OCR
jpaitken Jul 4, 2017
39a4a31
Merge branch 'develop' of https://github.com/AT-03/coding into featur…
jpaitken Jul 4, 2017
6c133bb
Banck OCR
jpaitken Jul 4, 2017
5855a0e
Update checkstyle.xml
jpaitken Jul 4, 2017
7abefda
Banck OCR
jpaitken Jul 4, 2017
0a04067
Banck OCR
jpaitken Jul 4, 2017
f590499
Banck OCR
jpaitken Jul 4, 2017
6cb5022
fixes
jpaitken Jul 4, 2017
046aebf
fixes
jpaitken Jul 5, 2017
7e8f940
Merge branch 'develop' of https://github.com/jpaitken/coding into fea…
jpaitken Jul 6, 2017
a1203e8
solved conflicts
jpaitken Jul 6, 2017
ce007ca
improve
jpaitken Jul 7, 2017
501fbd5
improved
jpaitken Jul 7, 2017
e4aebe2
improved
jpaitken Jul 7, 2017
0f878af
improved
jpaitken Jul 7, 2017
444945d
fixes
jpaitken Jul 8, 2017
7495ae9
fixes
jpaitken Jul 8, 2017
fcc4b17
fixes
jpaitken Jul 8, 2017
11b3181
fixes
jpaitken Jul 8, 2017
63eacc6
fixes
jpaitken Jul 8, 2017
ad53230
fixes
jpaitken Jul 8, 2017
8a3d26c
fixes
jpaitken Jul 8, 2017
8700259
fixes
jpaitken Jul 8, 2017
b6a567e
fixes
jpaitken Jul 8, 2017
19d0968
fixes
Jul 10, 2017
2263a52
fixes
Jul 10, 2017
8209bc7
fixes
Jul 10, 2017
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
1 change: 1 addition & 0 deletions coding.iml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<module external.linked.project.id="coding" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
Expand Down
Empty file added git
Empty file.
214 changes: 214 additions & 0 deletions src/main/java/org/fundacionjala/coding/juan/bank/BankOCR.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
package org.fundacionjala.coding.juan.bank;

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

/**
* Created by Juan P on 26/03/2017.
*/
public final class BankOCR {

private static final Map<Integer, String> MAP_NUMBERS = new HashMap<>();

private static final int START_STRING = 0;
private static final int END_STRING = 3;
private static final int MODULE_NINE = 9;
private static final int MODULE_ELEVEN = 11;
private static final int SCANNED_LENGTH = 72;
private static final int QUANTITY_LENGTH = 9;

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;

static {
MAP_NUMBERS.put(ZERO,
" _ "
+ "| |"
+ "|_|");
MAP_NUMBERS.put(ONE,
" "
+ " |"
+ " |");

MAP_NUMBERS.put(TWO,
" _ "
+ " _|"
+ "|_ ");

MAP_NUMBERS.put(THREE,
"__ "
+ " _|"
+ "__|");

MAP_NUMBERS.put(FOUR,
" "
+ "|_|"
+ " |");

MAP_NUMBERS.put(FIVE,
" _"
+ "|_ "
+ " _|");

MAP_NUMBERS.put(SIX,
" _ "
+ "|_ "
+ "|_|");

MAP_NUMBERS.put(SEVEN,
" _ "
+ " |"
+ " |");
MAP_NUMBERS.put(EIGHT,
" _ "
+ "|_|"
+ "|_|");

MAP_NUMBERS.put(NINE,
" _ "
+ "|_|"
+ " _|");
}

/**
* Constructor.
*/

private BankOCR() {

}

/**
* @param value to get int.
* @return characters in a range 0-9
*/

private static String getKey(final String value) {
String valueString = "?";
for (Map.Entry<Integer, String> inputData : MAP_NUMBERS.entrySet()) {
valueString = inputData.getValue().equalsIgnoreCase(value)
? inputData.getKey().toString() : valueString;
}
return valueString;
}

/**
* @param numberScanned String
* @return true or false
*/

public static String convertStringToNumber(final String[] numberScanned) {
StringBuilder imageToString = new StringBuilder();

for (String numberString : numberScanned) {
imageToString.append(getKey(numberString));
}
return imageToString.toString();
}

/**
* This method validate account MAP_NUMBERS.
*
* @param account quantity.
* @return true or false.
*/

static boolean validateAccountNumbers(final String account) {
int sum = 0;
int factorMultiple = 9;
if ((account.length() == QUANTITY_LENGTH) && isLegible(account)) {
String[] accountSplit = account.split("");

for (String value : accountSplit) {
sum += Integer.parseInt(value) * factorMultiple;
factorMultiple--;
}
return sum % MODULE_ELEVEN == 0;
}
return false;
}

/**
* Method to validate if value is legible.
*
* @param account account.
* @return true or false.
*/
static boolean isLegible(final String account) {
Copy link
Contributor

Choose a reason for hiding this comment

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

you can still refactor this


for (int i = 0; i < account.length(); i++) {
if (!Character.isDigit(account.charAt(i))) {
return false;
}
}
return true;
}

/**
* This method return the value scanned.
*
* @param scanned value scanned.
* @return value string.
*/
static String accountRepresentation(final String[] scanned) {
StringBuilder acctRepresentation = new StringBuilder();

for (String string : scanned) {
acctRepresentation.append(getKey(string));
}

return String.valueOf(acctRepresentation);
}

/**
* Get status account.
*
* @param account account.
* @return ILL if isn't legible and ERR if not validate accounts MAP_NUMBERS.
*/
static String getStatusAccount(final String account) {
return !isLegible(account) ? "ILL" : !validateAccountNumbers(account) ? "ERR" : " ";
}

/**
* This method scans an image and returns string.
*
* @param account account.
* @return string[] with nine digits.
*/
static String[] parseScannedString(final String account) {

String[] scannedDigits = {"", "", "", "", "", "", "", "", ""};
int stringFinal = 3;

if (account.length() != SCANNED_LENGTH) {
int index = 0;
int start = START_STRING;
int end = END_STRING;
int indexModule = MODULE_NINE;

for (int i = 0; i < account.length(); i += stringFinal) {
index = index % indexModule;

scannedDigits[index] += account.substring(start, end);

start = end;
end += stringFinal;
index++;
}

return scannedDigits;
}
return scannedDigits;
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.fundacionjala.coding.juan.eanvalidator;

/**
* @author Juan Pablo
*/
public final class EanValidator {
/**
* constructor.
*/
private EanValidator() {

}

/**
* @param eanCode is the code provided as input.
* @return the validation.
*/
public static boolean validating(final String eanCode) {
char[] code = eanCode.toCharArray();
int checkSum = 0;
int digit = 0;
for (int i = 0; i < code.length; i++) {
digit = code[i];
checkSum += (i + 1) % 2 == 0 ? digit * 3 : digit;
}
digit = (code[code.length - 1]);
return checkSum % 10 == 0 || 10 - (checkSum % 10) == digit;
}
}
34 changes: 34 additions & 0 deletions src/main/java/org/fundacionjala/coding/juan/gas/Evaporator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.fundacionjala.coding.juan.gas;

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

/**
* Constructor.
*/
private Evaporator() {
}
private static final int PERCENT = 100;
/**
* Calculate the life of gas.
*
* @param content how much gas have.
* @param evap how much waste.
* @param threshold the limit.
* @return how many days.
*/
public static int evaporator(final double content, final int evap, final int threshold) {
int days = 0;
double cont = content;
double limit1 = content * threshold / PERCENT;
while (cont >= limit1) {
cont = cont - cont * evap / PERCENT;
days++;
}
return days;


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.fundacionjala.coding.juan.highestandlowest;

import java.util.Arrays;

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

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

/**
* Kata.
*
* @param number is the string of numbers
* @return the higtest and lowest numbers
*/
public static String hingAndLow(final String number) {
String[] numbers = number.split(" ");
Integer[] num = new Integer[numbers.length];
for (int i = 0; i < numbers.length; i++) {
num[i] = Integer.parseInt(numbers[i]);
}
Arrays.sort(num);
return String.format("%d %d", num[num.length - 1], num[0]);

}
}
31 changes: 31 additions & 0 deletions src/main/java/org/fundacionjala/coding/juan/movies/Children.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.fundacionjala.coding.juan.movies;

/**
* @author Juan Pablo
*/
public class Children extends Movie {
private static final int LIMINEWCHILD = 3;
private static final double PRICE = 1.5;

/**
* constructor.
* @param title is the title of the movie.
*/
public Children(final String title) {
super(title);
}

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

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