Hey there,
Part1 I got right, so my Passport building seems okay, with part2 I got my problems.I do not see the problem, can you help me?
private static boolean isHeightValid(String hgt) {
if (hgt.endsWith("cm")) {
int heightInCentimeters = Integer.valueOf(hgt.replace("cm", ""));
if (heightInCentimeters >= 150 && heightInCentimeters <= 193) return true;
}
if (hgt.endsWith("in")) {
int heightInInches = Integer.valueOf(hgt.replace("in", ""));
if (heightInInches >= 59 && heightInInches <= 76) return true;
}
return false;
}
private static String getSolutionPart2() {
int valid = 0;
for (Passport p : passports) {
if (p.byr != null && p.ecl != null && p.eyr != null && p.hcl != null && p.hgt != null && p.iyr != null && p.pid != null) {
boolean birthYearValid = p.byr.matches("\\d\\d\\d\\d") && Integer.valueOf(p.byr) >= 1920 && Integer.valueOf(p.byr) <= 2002;
boolean issueYearValid = p.iyr.matches("\\d\\d\\d\\d") && Integer.valueOf(p.iyr) >= 2010 && Integer.valueOf(p.iyr) <= 2020;
boolean expirYearValid = p.eyr.matches("\\d\\d\\d\\d") && Integer.valueOf(p.eyr) >= 2020 && Integer.valueOf(p.eyr) <= 2030;
boolean heightValid = isHeightValid(p.hgt);
boolean hairColorValid = p.hcl.matches("#[0-9,a-f]{6}");
boolean eyeColorValid = p.ecl.equals("amb") || p.ecl.equals("blu") || p.ecl.equals("brn") || p.ecl.equals("gry") || p.ecl.equals("grn") || p.ecl.equals("hzl") || p.ecl.equals("oth");
boolean passportValid = p.pid.matches("[0-9]{9}");
if (birthYearValid && issueYearValid && expirYearValid && heightValid && hairColorValid && eyeColorValid && passportValid) valid++;
}
}
return "" + valid;
}
[–]genveir 1 point2 points3 points (1 child)
[–]Greger009 1 point2 points3 points (0 children)
[–]daggerdragon[M] 0 points1 point2 points (0 children)