-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding validation to validateCandidates and findMinEvenNumber
- Loading branch information
Showing
2 changed files
with
34 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,18 +1,25 @@ | ||
package practice; | ||
|
||
import model.Candidate; | ||
|
||
import java.util.function.Predicate; | ||
import model.Candidate; | ||
|
||
public class CandidateValidator implements Predicate<Candidate> { | ||
|
||
@Override | ||
public boolean test(Candidate candidate) { | ||
String[] PeriodsInUkr = candidate.getPeriodsInUkr().split("-"); | ||
periodsInUkrValidator(candidate); | ||
String[] periodsInUkr = candidate.getPeriodsInUkr().split("-"); | ||
return candidate.getAge() >= 35 | ||
&& candidate.getNationality().equals("Ukrainian") | ||
&& candidate.isAllowedToVote() | ||
&& Integer.parseInt(PeriodsInUkr[1]) - Integer.parseInt(PeriodsInUkr[0]) > 10; | ||
&& Integer.parseInt(periodsInUkr[1]) - Integer.parseInt(periodsInUkr[0]) > 10; | ||
} | ||
|
||
private void periodsInUkrValidator(Candidate candidate) { | ||
for (int i = 0; i < candidate.getPeriodsInUkr().length(); i++) { | ||
if (Character.isLetter(candidate.getPeriodsInUkr().charAt(i))) { | ||
throw new RuntimeException("Data contains letters"); | ||
} | ||
} | ||
} | ||
//write your code here | ||
} |
This file contains 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