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
A new drug to combat acne has been developed from a compound that is found in a melon. Which scientists would contribute to the
Ann [662]
The correct answer for this question is this one: "B. biologists and chemists."  A new drug to combat acne has been developed from a compound that is found in a melon. The <span>scientists would contribute to the development of the drug are biologists and chemists.
</span>
Here are the choices:
A. <span>chemists only
B. biologists and chemists
C. biologists, chemists, and physicists
D. biologists, chemists, and physicians</span>
8 0
4 years ago
Read 2 more answers
Quick question;
insens350 [35]

A company could benefit from data mining finding valuables in said data. They could use it to earn bitcoin which can be cashed out. Also they can find hidden items unreleased in files.

hope this helps! :D

8 0
3 years ago
When you gather primary or secondary data, what part of the market information management process are you participating in?
Umnica [9.8K]

Answer:

Heyyyooo!

The answer is market research.

Hope this helps!

Explanation:

Market research is the way toward gathering, analyzing and interpreting data about a market, about an item or administration to be offered available to be purchased in that advertise, and about the past, present and potential clients for the item or administration; examination into the attributes, ways of managing money, area and necessities of your business' objective market, the industry all in all, and the specific contenders you confront.  

3 0
3 years ago
Write a program to input the length and width of a rectangle and calculate and print the perimeter and area of the rectangle.
Phantasy [73]

\tt L=(float(input("Enter\:Length\:of\:rectangle=")))

\tt B=(float(input("Enter\:Breadth\:of\:the\:rectangle=")))

\tt P=2*(L+B)

\tt A=L*B

\tt print("Perimeter\:of\:the\:rectangle=",P)

\tt print("Area\:of\:the\:rectangle=",A)

7 0
3 years ago
Which tab on the Ribbon contains the command to show the slide show from the current slide?
hichkok12 [17]

Answer:

The answer to this question is given below in the explanation section.

Explanation:

The correct answer to this question is B: Slide Show.

You can use the Slide Show tab on the ribbon that contains commands to show the slide show from the current slide. As you click on the Slide Show tab on the ribbon, you see a group of commands name "Start Slide Show", in these group of command, there is an option to start slide show From Current Slide. when you will click this option the slide show will start from your current slide.

Other options are not correct because:

The home tab on the ribbon contains commands related to slide, font, paragraph, editing, etc. File tab contains commands related to opening new or existing presentation documents and saving them, etc. While the View tab on the ribbon has a group of commands related to presentation view, master, zoom, etc. These tabs are used to show the slide show from the current slide.  

3 0
3 years ago
Other questions:
  • Which is a method used to determine database requirement?
    15·1 answer
  • Customer A with a Bronze service level package calls in a Critical System Failure at 9:00 AM. Customer B with a Silver service l
    15·1 answer
  • Inserting diagrams into documents can help readers better understand document text. True or False?
    10·1 answer
  • True or False?If you live in a country that uses censorship,you may not be able to access certain websites.ONLY ANSWER IF UR 100
    9·2 answers
  • In the _____ phase of transferring data from a transactional database to a data warehouse, the builders create the files from tr
    15·1 answer
  • Seeking additional information is known as _____.
    12·2 answers
  • Mika forgot to put in the function name in his function header for the code below. What would be the best function header?
    12·2 answers
  • True or False? Jerry's company is beginning a new project, and he has been assigned to find a telecommunications tool that will
    13·2 answers
  • Evaluate the following expression: <br> 12+(2**4-5)/2Required to answer. Single choice.
    10·1 answer
  • What is a . com in a web address mean<br>​
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!