1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Papessa [141]
3 years ago
7

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.");
}
}
Computers and Technology
1 answer:
Brrunno [24]3 years ago
3 0

Answer:

Explanation:

The code provided is already taking in the input and comparing it to the current date using the methods isBefore(), isAfter(), and equals(). It works perfectly and did not need any changes to the code. As you can see from the attached pictures below, every scenario works as intended. If the format is not correct and the date object is not able to be created then it prompts an error message and exits the program as intended.

import java.util.*;

import java.time.LocalDate;

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.");

   }

}

You might be interested in
What the repeal of online privacy protections means for you?
kvv77 [185]
Online Privacy is well, our privacy while on the internet. If they have repealed that, then we have no privacy while on the internet. I feel like now a days there is no privacy at all anywhere. Everywhere you go, there are cameras watching you. So for them to take away online privacy is pretty messed up.
7 0
4 years ago
How desktop case or chassis designed?, material and steps?​
MariettaO [177]

They may require things such as plastic cut outs and glass depending if you want to be able to have a window to look into the pc. Some cases are 3D Printed although they have to be joined by screws at the end due to the fact that one whole print can take over a week and then it has to be well doesn't but looks better when sanded.

3 0
2 years ago
Ummm, I hate to interrupt your day, but does anyone know where Mitch72 is????? Because he hasn't talked in a week, and he hasn't
Anettt [7]

Answer:

sorry but no

Explanation:

4 0
3 years ago
What information should be included in the closing paragraph of a thank-you letter? a. Mention skills that were omitted during t
stiks02 [169]
The answer is c and sorry for being so rude I didn't realize it was you girly

3 0
4 years ago
Read 2 more answers
If you have a Gmail account, you automatically have a Google+ account
Korolek [52]
The statement above is TRUE.
According to Google operating system, new users who signed up for google account will automatically get a gmail and google plus accounts. User can later delete the google plus account if they are not interested in it.
5 0
3 years ago
Other questions:
  • Before entering a loop, the first input, or ____, is retrieved.
    14·1 answer
  • Which dialog box opens after selecting a cell in the list of prepared data, clicking the insert tab on ribbon and the clicking t
    6·1 answer
  • What is Administrator windows 10
    8·1 answer
  • This decision control structure enables the program to execute a statement or block of codes if and only if the Boolean expressi
    7·1 answer
  • Angelika just submitted her product for the first time, and she had 2 errors, 3 warnings, and 5 notifications. What does she nee
    7·2 answers
  • A weighted GPA counts__more highly.
    12·1 answer
  • What is cloud computing?
    9·1 answer
  • The Internet:
    12·1 answer
  • What standards organization maintains the ethernet standard?.
    12·1 answer
  • PLEASE HELP. Nobody has been helping me, i need to resolve this code issue for game design
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!