Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions