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

Question: You will be writing a program that will prompt the user for a date and

ID: 674613 • Letter: Q

Question

Question: You will be writing a program that will prompt the user for a date and a time. For the date, the user will be asked to enter in three integers (month, day, year). There will be four functions related to the date:

Next, the user will be asked to enter the time, which is to be then converted from military time and displayed. There will be three functions related to the time:

int getHours() - Prompts the user for an integer resembling the hour of the day in military time. If the user enters 23, the function should return 11. If the military time entered is >=12, set the global boolean variable PM to be true, else false. int getMinutes() - Prompts the user for an integer resembling the minutes and returns that integer. void displayTime(int hour, int min) - This function will check if the global boolean variable PM is true. If it is true, display the time in this format: 12:34 PM. If PM is false, display the time as so: 11:34 AM

For each "get" function, there should be an input-validation loop. The purpose for this lab is to allow you to become more comfortable with declaring functions, calling functions, and defining functions.

Explanation / Answer

import java.util.*;
import java.text.DateFormatSymbols;
class a
{
   int day, month, year, hour, min;
   String period="Am";
   a()
   {

   }

   String getMonth()
   {
       Scanner o=new Scanner(System.in);  

      
       System.out.println("Enter month");
       month = Integer.parseInt(o.nextLine());
       return new DateFormatSymbols

().getMonths()[month-1];
   }


   int getDay()
   {     
       Scanner o=new Scanner(System.in);  

          
       System.out.println("Enter day of

month");
       day = Integer.parseInt(o.nextLine());
       return day;
   }

   int getYear()
   {
       Scanner o=new Scanner(System.in);  
       System.out.println("Enter Year");
       year = Integer.parseInt(o.nextLine());
       return year;
   }
  
   void displayDate(String mo, int day, int year)
   {
       System.out.println(mo+" " +day+",

"+year);
   }

   int getHours()
   {
       Scanner o=new Scanner(System.in);  

       System.out.println("Enter Hours");
       hour= Integer.parseInt(o.nextLine());
       if(hour>12)
       {
           hour = hour - 12;
          period = "Pm";
       }
       return hour;
   }

   int getMinutes()
   {
       Scanner o=new Scanner(System.in);  
       System.out.println("Enter Minutes");
       min= Integer.parseInt(o.nextLine());
       return min;
   }

   void displayTime(int h, int min)
   {
       System.out.println(h+":"+min+period);
   }  
}
class date_conv
{
   public static void main(String args[])
   {
       a o =new a();

       int d, y, h, mi;
       String m;

       d=o.getDay();
       m=o.getMonth();
       y=o.getYear();

       o.displayDate(m,d,y);

       h=o.getHours();
       mi=o.getMinutes();
       o.displayTime(h,mi);
   }
}


      

      

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