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
Driving at slower speeds than traffic flow _____________ .
UNO [17]
The answer is B. may impede other vehicles on the road that are traveling at a normal and safe speeds
4 0
3 years ago
C++ program: Write a program that prompts the user to input three numbers. The program should then output the numbers in ascendi
Lelechka [254]

Answer:

// here is code in C++.

#include<iostream>

using namespace std;

int main()

{

// declare variables

  double num1, num2, mun3, t;

  cout << "Enter three numbers: ";

// read the three numbers

  cin >> num1 >> num2 >> mun3;

  //sort the three numbers

  if( num1>num2 )

  {

     t = num1;

     num1 = num2;

     num2 = t;}

  if( num2>mun3 ){

     t = num2;

     num2 = mun3;

     mun3 = t;}

  if( num1>num2 ){

     t = num1;

     num1 = num2;

     num2 = t;

  }

  // print the output

  cout<<"numbers in ascending order:";

  cout << num1 << " " << num2 << " " << mun3 << endl;

  return 0 ;

}

Explanation:

Declare three variables to store the input. Read the value of all three variables. If first number is greater than second, then with the help of variable "t" swap the  value of first and second.after that if second is greater than third number, swap them.In last if first number is greater than second one then swap them. This will sort the three numbers in ascending order.

Output:

Enter three numbers: 3 7 2                                                                                                

numbers in ascending order:2 3 7

3 0
3 years ago
Select all the correct answers. Which two statements are true about an OS? translates the user's instructions into binary to get
Studentka2010 [4]

Answer:

C. is responsible for memory and device management.

E. is responsible for system security.

Explanation:

An operating system platform is a system software pre-installed on a computing device to manage or control software application, computer hardware and user processes.

This ultimately implies that, an operating system (OS) is essentially an interface between the computer’s hardware and all the software applications (programs) running on it.

Some examples of an operating system are QNX, Linux, OpenVMS, MacOS, Microsoft windows, IBM, Solaris, VM, Ubuntu, etc.

The two statements which are true about an operating system (OS) are;

I. It's responsible for memory and device management. The operating system (OS) ensures proper allocation of memory to processes and manages all the input/output devices that are connected to the computer.

II. It's responsible for system security. The operating system (OS) makes sure the data integrity of a computer system isn't compromised i.e determining whether or not a request is to be processed through an authentication process.

6 0
3 years ago
Vivian wants to use shorthand properties for a background for her new website. What would be the proper element?
KiRa [710]
1. There are two equivalent options: 
     <span>2. border-width:2px; 
         border-style:solid; 
         border-color: #000 
and </span><span>3. border: 2px solid #000;

As for programmers: "Shorter = better". So option 3 is your choice.

2. I think it's a very tricky question and I can't see correct answer. But in my opinion this one is the most possible: </span><span>3. CSS shorthand take up less space. Shorter files = less mistakes.</span>
5 0
3 years ago
How do you copy and paste
AVprozaik [17]

Answer:

ctrl+c=copy

ctrl+v=paste

Explanation:

5 0
3 years ago
Read 2 more answers
Other questions:
  • As computers become faster, memory access speeds are not keeping pace. Question 5 options: True False
    7·1 answer
  • which of the following is involved in ordering an outline. A.grouping B.merging C.organizing D.arranging
    10·1 answer
  • What does it mean to have liability for a company?
    6·1 answer
  • An increase in pay because of how well you do a job is called _____.
    9·2 answers
  • Given a String variable named line1, write a sequence of statements that use a Scanner to read the first line of a file named "p
    7·1 answer
  • Setting up the initial values for the min and max depends on whether n is odd or even. If n is even, compare the first two eleme
    15·1 answer
  • A systems engineer suspects a new type of malware has impacted the company network. Which threat hunting approach does the engin
    7·1 answer
  • Which line of code could be used for a constructor?
    9·1 answer
  • The multiprocessor system which consists of a set of processors that share a common main memory and are under the integrated con
    13·1 answer
  • Copying materials from a source text without using is<br> considered plagiarism<br> ?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!