Write the following in Java
In this section, you will overload methods to display
dates. The date-displaying methods might be used by many different
applications in an organization, such as those that schedule jobs,
appointments, and employee reviews. The methods take one, two, or
three integer arguments. If there is one argument, it is the month,
and the date
becomes the first day of the given month in the year 2020. If there
are two arguments, they are the month and the day in the year 2020.
Three arguments represent the month, day, and year.
Create the displayDate() method that requires
one parameter to
represent the month and uses default values for the day and year.
Use println method to display the date as following:
Event date: mm/1/2020
Create the displayDate() method that requires
two parameters to
represent the month and day and uses a default value for the year.
Use println method to display the date as follows:
Event date: mm/dd/2020
Create the displayDate() method that requires
three parameters
used as the month, day, and year. Use println method to display the
date as follows:
Event date: mm/dd/yyyy
Create a main method. In the main method, test
the above three methods.
Please find the code, inline comments and output below.
public class Main
{
// overloading of displayDate method
// If there is one argument, it is the month, and the date
// becomes the first day of the given month in the year 2020.
public static void displayDate(int mm){
System.out.println("Event Date: "+mm+"/1/2020");
}
// If there are two arguments, they are the month and the day in
the year 2020.
public static void displayDate(int mm , int dd){
System.out.println("Event Date: "+mm+"/"+dd+"/2020");
}
// Three arguments represent the month, day, and year.
public static void displayDate(int mm, int dd, int yyyy){
System.out.println("Event Date: "+mm+"/"+dd+"/"+yyyy);
}
public static void main(String[] args) {
// Calling the functions in the main
displayDate(07);
displayDate(07,24);
displayDate(07,24,1995);
}
}
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.