Question: Part A Write an application called PastPresentFuture that uses the LocalDate class to access the current date. Prompt a user for a month, day, and
Part A
Write an application called PastPresentFuture that uses the LocalDate class to access the current date.
Prompt a user for a month, day, and year. Display a message that specifies whether the entered date is
not this year,
in an earlier month this year,
in a later month this year, or
this month.
An example of the program is shown below:
Enter a month
Enter a day
Enter a year
four digits
is this month
Part B
Copy the code from your PastPresentFuture program into PastPresentFuture
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, the current date, or in the future.
Task
: Create the PastPresentFuture class.
Task
: The program returns the correct response for a date matching the current month.
Task
: The program returns the correct response for a date in the past.
Task
: The program returns the correct response for a date in the future.
Task
: The program returns the correct response for a date not in the current year.
Task
: Create the PastPresentFuture
class
Task
: The PastPresentFuture
program implements isBefore
isAfter
or equals
public class PastPresentFuture
public static void mainString args
Scanner scanner new ScannerSystem in;
LocalDate currentDate LocalDate. now;
Prompt user for month, day, and year
System.out.printEnter a month ;
int month scanner. nextint;
System.out.printEnter a day ;
int day scanner.nextint;
System.out.printEnter a year four digits;
int year scanner.nextint;
LocalDate enteredDate LocalDate.ofyear month, day;
Compare entered date with current date
if enteredDategetYear currentDate.getYear
System.out.print lnmonth is not this year";
else if enteredDategetMonth currentDate.getMonth
System.out.printlnmonth is this month";
else if enteredDateisAftercurrentDate
System.out.printlnmonth is in a later month this year";
else
System.out.printlnmonth is in an earlier month this year"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
