Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ming Exercise 5-5B Instructions PastPresentFut.... 1 import java.util.*; 2 impor

ID: 3745707 • Letter: M

Question

ming Exercise 5-5B Instructions PastPresentFut.... 1 import java.util.*; 2 import java. tine. * 3 public class PastPresentFuture2 Use the web to learn how to use the LocalDate Boolean methods isBefore), isAfter , and equals) . Use your knowledge to write a program that prompts a user for a month, day, and year, and then displays a message specifying whether the entered day is in the past, is today (the current date), or is in the future. 5 public static votd main (String, argst 1 LocalDate today LocalDate.now(); LocalDate enteredDate; 9-int no, da, yr; 10 int todayMo, todayDa, todayYr: Scanner input new Scanner (Systen. in),; Systen.out.print( Enter a month >>; no input.nextInt(); System.out.print( Enter a day; Grading 12 13 Write your Java code in the area on the right. Use the Run button to compile and run the code. Clicking the Run Checks button will run pre-configured tests against your code to calculate a grade. 15 da Lnput.nextIntO; 16 17 18 19 I/ Write your code here 20 21 System.out.print("Enter a year (four digits) > yr input.nextInto; Once you are happy with your results, click the Submit button to record your score. 23

Explanation / Answer

import java.time.*; import java.util.*; public class PastPresentFuture2 { public static void main(String[] args) { LocalDate today = LocalDate.now(); LocalDate enteredDate; int mo, da, yr; int todayMo, todayDa, todayYr; Scanner input = new Scanner(System.in); System.out.print("Enter a month >> "); mo = input.nextInt(); System.out.print("Enter a day >> "); da = input.nextInt(); System.out.print("Enter a year (four digits) >> "); yr = input.nextInt(); enteredDate = LocalDate.of(yr, mo, da); if(enteredDate.isBefore(today)) { System.out.println("Entered date is in the past"); } else if(enteredDate.isAfter(today)) { System.out.println("Entered date is in the future"); } else { System.out.println("Entered date is today"); } } }