OCA Quiz 5A

  • public class LocalTimeTest2 {
      public static void main(String[] args) {
        LocalDate aDate = LocalDate.now(); // line 1
        dayLightSavings(aDate); // line 2
       }
      private static void dayLightSavings(LocalDate myDateTime) {
        LocalDateTime ldt = myDateTime.plusHours(1); // line 3
        System.out.println(ldt);
      }
    }
  • public class LocalTimeTest {
      public static void main(String[] args) {
        LocalDate start = LocalDate.of(2021, 6, 5); //line 1
        LocalDate end = LocalDate.of(2021, Month.JUNE, 18); //line 2
        LocalTimeTest.inefficientWayToCountDaysLeft(start, end);
      }
    private static void inefficientWayToCountDaysLeft(LocalDate start, LocalDate end) {
      int counter = 0;
      while(start.isBefore(end)) {//line 3
         counter++;
         start.plusDays(1);
         System.out.println(start.getDayOfMonth());
    }
        System.out.printf("There are %d days left", counter);
      }
    }
  • public class LocalTimeTest3 {
      public static void main(String[] args) {
        LocalDate start = LocalDate.of(2021, 6, 5);
        Period newPeriod = Period.ofYears(1).ofWeeks(1);
        LocalDate end = start.plus(newPeriod);
         System.out.println(end.toString());
      }
    }