Question: My code is not running correctly and I am not sure why. Usually anything I enter reads as the current date. The question : Use

My code is not running correctly and I am not sure why. Usually anything I enter reads as the current date.

The question :

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. Save the file as PastPresentFuture2.java

My code:

import java.util.Scanner; import java.time.LocalDate;

public class PastPresentFuture2 { static final int month = 0; static final int day = 0; static final int year = 0; public static void main(String[] args) { Scanner enter = new Scanner(System.in); LocalDate currentDate = LocalDate.now(); System.out.println("Enter year"); int year = enter.nextInt(); System.out.println("Enter month"); int month = enter.nextInt(); System.out.println("Enter day"); int day = enter.nextInt(); LocalDate inputDate = LocalDate.of(year,month,day); if (inputDate.isBefore(currentDate)) { System.out.println("This date is the current date."); } else if (inputDate.isAfter(currentDate)) { System.out.println("This date is in the future."); } else if (inputDate.isEqual(currentDate)) { System.out.println("This is the current date."); } }

}

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!