1. import java.time.Month;
    2. import java.time.Year;
    3. import java.time.LocalDate;
    4. import java.time.DayOfWeek;
    5. import java.time.DateTimeException;
    6. import java.time.temporal.TemporalQuery;
    7. import java.time.temporal.TemporalAccessor;
    8. import java.io.PrintStream;
    9. public class Superstitious {
    10. public static void main(String[] args) {
    11. Month month = null;
    12. LocalDate date = null;
    13. if (args.length < 2) {
    14. System.out.printf("Usage: Superstitious <month> <day>%n");
    15. throw new IllegalArgumentException();
    16. }
    17. try {
    18. month = Month.valueOf(args[0].toUpperCase());
    19. } catch (IllegalArgumentException exc) {
    20. System.out.printf("%s is not a valid month.%n", args[0]);
    21. throw exc; // Rethrow the exception.
    22. }
    23. int day = Integer.parseInt(args[1]);
    24. try {
    25. date = Year.now().atMonth(month).atDay(day);
    26. } catch (DateTimeException exc) {
    27. System.out.printf("%s %s is not a valid date.%n", month, day);
    28. throw exc; // Rethrow the exception.
    29. }
    30. System.out.println(date.query(new FridayThirteenQuery()));
    31. }
    32. }
    1. import java.time.Month;
    2. import java.time.Year;
    3. import java.time.LocalDate;
    4. import java.time.DateTimeException;
    5. import java.time.temporal.TemporalQuery;
    6. import java.time.temporal.TemporalAccessor;
    7. import java.time.temporal.ChronoField;
    8. import java.io.PrintStream;
    9. import java.lang.Boolean;
    10. public class FridayThirteenQuery implements TemporalQuery<Boolean> {
    11. // Returns TRUE if the date occurs on Friday the 13th.
    12. public Boolean queryFrom(TemporalAccessor date) {
    13. return ((date.get(ChronoField.DAY_OF_MONTH) == 13) &&
    14. (date.get(ChronoField.DAY_OF_WEEK) == 5));
    15. }
    16. }