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
(
1
)
not this year,
(
2
)
in an earlier month this year,
(
3
)
in a later month this year, or
(
4
)
this month.
An example of the program is shown below:
Enter a month
>
>
7
Enter a day
>
>
2
0
Enter a year
(
four digits
)
>
>
2
0
2
1
7
is this month
Part B
Copy the code from your PastPresentFuture program into PastPresentFuture
2
.
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
0
1
: Create the PastPresentFuture class.
Task
0
2
: The program returns the correct response for a date matching the current month.
Task
0
3
: The program returns the correct response for a date in the past.
Task
0
4
: The program returns the correct response for a date in the future.
Task
0
5
: The program returns the correct response for a date not in the current year.
Task
0
6
: Create the PastPresentFuture
2
class.
Task
0
7
: The PastPresentFuture
2
program implements isBefore
(
)
,
isAfter
(
)
,
or equals
(
)
.public class PastPresentFuture {
public static void main(String[] args){
Scanner scanner = new Scanner(System. in);
LocalDate currentDate = LocalDate. now();
// Prompt user for month, day, and year
System.out.print("Enter a month ");
int month = scanner. nextint();
System.out.print("Enter a day ");
int day = scanner.nextint();
System.out.print("Enter a year (four digits)");
int year = scanner.nextint();
LocalDate enteredDate = LocalDate.of(year, month, day);
// Compare entered date with current date
if (enteredDate.getYear()!= currentDate.getYear()){
System.out.print ln(month +" is not this year");
}) else if (enteredDate.getMonth()= currentDate.getMonth()){
System.out.println(month +" is this month");
} else if (enteredDate.isAfter(currentDate)){
System.out.println(month +" is in a later month this year");
} else {
System.out.println(month +" is in an earlier month this year"
}
}
 Part A Write an application called PastPresentFuture that uses the LocalDate

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!