subject

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. import java. util.*;
import java. time. LocalDate;
public class PastPresentFuture2
{
public static void main(String args[])
{
int mo, da, yr;
LocalDate today=LocalDate. now();
System. out. println("Program to find if the given date is in past, present or future::");
Scanner input=new Scanner(System. in);
//taking inputs from console and storing them in three variables.
System. out. print("Enter month::");
mo=input. nextInt();
System. out. print("Enter day::");
da=input. nextInt();
System. out. print("Enter year::");
yr=input. nextInt();
//creating a LocalDate object and initializing it to null;
LocalDate inputDate=null;
try
{
/*we are using the 3 variables and converting it into a date object to compare it with today's date */
inputDate = LocalDate. of(yr, mo, da);
}
catch(Exception ex)
{
/*if the entered day, month & year are not converted to a date object because of invalid entry of any values, we are stopping the program.*/
System. out. println("You have made invalid entries, please try again !!");
System. exit(0);
}
/*if the date object is created after proper entries, we are using the built-in functions to compare it the today's date object*/
System. out. print("The date you entered is ");
if(inputDate. isBefore(today))
System. out. println("in the past.");
else
if(inputDate. isAfter(today))
System. out. println("in the future.");
else
if(inputDate. equals(today))
System. out. println("the current date.");
}
}

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 01:00, kmsg2000
Program description: a c# app is to be created to produce morse code. the morse code assigns a series of dots and dashes to each letter of the alphabet, each digit, and a few special characters (such as period, comma, colon, and semicolon). in sound-oriented systems, the dot represents a short sound and the dash represents a long sound. separation between words is indicated by a space, or, quite simply, the absence of a dot or dash. in a sound-oriented system, a space is indicated by a short period of time during which no sound is transmitted. the international version of the morse code is stored in the data file morse. txt.
Answers: 3
image
Computers and Technology, 22.06.2019 11:30, LindseyN1
One subtask in the game is to roll the dice. explain why is roll the dice an abstraction.
Answers: 3
image
Computers and Technology, 23.06.2019 16:00, ginaaa20
Which analyst position analyzes information using mathematical models to business managers make decisions?
Answers: 1
image
Computers and Technology, 23.06.2019 20:50, terryhgivens5349
3.11.3 quiz: comparing and analyzing function typesquestion 4 of 102 pointswhat can you say about the y-values of the two functions f(x) = 3x2-3 andg(x)=2* - 3?
Answers: 2
You know the right answer?
Use the web to learn how to use the LocalDate Boolean methods isBefore(), isAfter(), and equals(). U...

Questions in other subjects:

Konu
Business, 23.08.2019 04:00
Konu
Biology, 23.08.2019 04:00