Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3, write a program called Dateconversion Java whose main method takes a date as

ID: 3839374 • Letter: 3

Question

3, write a program called Dateconversion Java whose main method takes a date as an integer in the format MMDDYYYY from the user. The main will call a function input date conversion (avadoc and method signature is shown below) with the given and the method will return date converted in the required format. The month and the i e date conversion (12252016) will return December 25, 2016. of May, will day will always be given as two digits, including leading zero. ie 27th be entered as os272017 and the 1st of July, 2017 will be entered as Your Function must deal with the input parameter as an integer throughout your function and not convert it to string.

Explanation / Answer

Hi,

Please see below the class.

Please comment for any queries/feedbacks.

Thanks.

DateCoversion.java

import java.util.Scanner;

/**
* Class DateCoversion
* Converts the input int date to Formatted Date string
* @author
*
*/
public class DateCoversion {
   public static void main(String[] args){
       Scanner scan= new Scanner(System.in);
       int dateInput = 0;
       String dateFormatted= "";
       //Reading the Date from user
       System.out.println("Please enter the Date in MMDDYYYY format:");
       dateInput = scan.nextInt();

       //Calling date_conversion method
       dateFormatted = date_conversion(dateInput);
      
       //Displaying the formatted Date
       System.out.println(dateFormatted);

   }

   /**
   * date_conversion - to convert the input int date to formatted date
   * @param dateIn
   * @return
   */
   public static String date_conversion(int dateIn){
       String formattedDate= "";
       int month = dateIn / 1000000; //getting the month number
       String monthStr = getMonth(month); //Calling getMonth, to get the corresponding Month String for monthNumber
       formattedDate = formattedDate +monthStr+" ";
      
       int date = (dateIn / 10000) % 100; // Getting the date digits
       formattedDate = formattedDate +date+", ";
      
       int year = dateIn % 10000; // Getting the year digits
       formattedDate = formattedDate +year;
      
       return formattedDate;
   }
   /**
   * getMonth - to get the corresponding Month String for monthNumber
   * @param monthNum
   * @return
   */

   public static String getMonth(int monthNum){
       String monthStr = "";
       if(monthNum == 1){
           monthStr = "January";
       }
       else if(monthNum== 2 ){
           monthStr = "February";
       }
       else if(monthNum== 3){
           monthStr ="March";
       }
       else if(monthNum== 4){
           monthStr ="April";
       }
       else if(monthNum== 5 ){
           monthStr = "May";
       }else if(monthNum==6 ){
           monthStr = "June";
       }
       else if(monthNum==7 ){
           monthStr = "July";
       }
       else if(monthNum== 8){
           monthStr = "August";
       }
       else if(monthNum== 9){
           monthStr = "September";
       }
       else if(monthNum== 10){
           monthStr = "October";
       }
       else if(monthNum== 11){
           monthStr = "November";
       }
       else if(monthNum== 12){
           monthStr = "December";
       }

       return monthStr;

   }
}

Sample output:

Please enter the Date in MMDDYYYY format:
12252016
December 25, 2016

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote