-
Notifications
You must be signed in to change notification settings - Fork 10
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
jpaitken
wants to merge
48
commits into
AT-03:develop
Choose a base branch
from
jpaitken:feature/allKatas
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
7d86ee0
commit1
jpaitken 772d31e
commit2 with gradle check
jpaitken 431fc30
Delete bank_Machinne.java
jpaitken 0770a7a
Update EanValidator.java
jpaitken 667db53
commit3
jpaitken 175b1fd
commit MOVIES
jpaitken ebd41d3
commit 26/3
jpaitken 93f81bf
Commit Test
jpaitken 4081f11
BankCommit - firts
jpaitken 3800786
katas
jpaitken 4349bce
All Katas
jpaitken d6953c2
Merge branch 'develop' into feature/allKatas
jpaitken 268d209
All Katas
jpaitken dae303b
Merge remote-tracking branch 'origin/feature/allKatas' into feature/a…
jpaitken 7670dc4
Merge branch 'develop' of https://github.com/AT-03/coding into featur…
jpaitken 6e0be4e
Code improved
jpaitken 19a464d
Code improved
jpaitken 9896805
ternary condition on EanValidator
jpaitken baccd7e
Test refactored
jpaitken ead8057
SpinWords refactored.
jpaitken 04abfb4
New coverage.
jpaitken 244b99a
Banck OCR
jpaitken 39a4a31
Merge branch 'develop' of https://github.com/AT-03/coding into featur…
jpaitken 6c133bb
Banck OCR
jpaitken 5855a0e
Update checkstyle.xml
jpaitken 7abefda
Banck OCR
jpaitken 0a04067
Banck OCR
jpaitken f590499
Banck OCR
jpaitken 6cb5022
fixes
jpaitken 046aebf
fixes
jpaitken 7e8f940
Merge branch 'develop' of https://github.com/jpaitken/coding into fea…
jpaitken a1203e8
solved conflicts
jpaitken ce007ca
improve
jpaitken 501fbd5
improved
jpaitken e4aebe2
improved
jpaitken 0f878af
improved
jpaitken 444945d
fixes
jpaitken 7495ae9
fixes
jpaitken fcc4b17
fixes
jpaitken 11b3181
fixes
jpaitken 63eacc6
fixes
jpaitken ad53230
fixes
jpaitken 8a3d26c
fixes
jpaitken 8700259
fixes
jpaitken b6a567e
fixes
jpaitken 19d0968
fixes
2263a52
fixes
8209bc7
fixes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
214 changes: 214 additions & 0 deletions
214
src/main/java/org/fundacionjala/coding/juan/bank/BankOCR.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
||
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; | ||
} | ||
} | ||
|
||
|
29 changes: 29 additions & 0 deletions
29
src/main/java/org/fundacionjala/coding/juan/eanvalidator/EanValidator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
src/main/java/org/fundacionjala/coding/juan/gas/Evaporator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/org/fundacionjala/coding/juan/highestandlowest/HightestAndLowest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
src/main/java/org/fundacionjala/coding/juan/movies/Children.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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