1 import java.io.*;
 2 
 3 public class Main {
 4 
 5     static String amPM;//will hold am/pm for standard time
 6     static String traditionalTime;//will store traditional time from user
 7     static int mins1, mins2, hours;//will store hours and minutes
 8 
 9     public static void main(String[] args) throws IOException {
10         // TODO code application logic here
11       BufferedReader br = new BufferedReader (new InputStreamReader (System.in));// user input
12 
13     int tryAgain=1;//will initial do-while loop
14     System.out.println("Standard Time to Traditional Time Converter");
15     System.out.println("===========================================");
16     do{
17     System.out.println();
18     System.out.println("Input a time in Standard Form (HH:MM:SS):");
19     String standardTime=br.readLine();//user inputs time in standard form
20     System.out.println();
21 
22 
23 
24     do{
25     if ((standardTime.length())!=8){
26     System.out.println("Invalid time entered.");
27     System.out.println("Input a time in Standard Form that has this form HH:MM:SS ...");
28     standardTime=br.readLine();//user inputs time in standard form
29     System.out.println();
30     }
31     }while((standardTime.length())!=8);
32 
33     convertToTraditional(standardTime);
34 
35     System.out.println(standardTime+" is equivalent to "+traditionalTime);
36     System.out.println();
37     System.out.println("Enter 1 to try again.");
38     tryAgain=Integer.parseInt(br.readLine());//user decides to try again
39     }while(tryAgain==1);//will repeat if user enters 1
40 
41  }//closes main body
42 
43  public static void convertToTraditional(String standardTime){//sub routine will convert standard to traditional
44 
45  char H1, H2, M1, M2;
46  H1 = standardTime.charAt(0);
47  H2 = standardTime.charAt(1);
48  M1 = standardTime.charAt(3);
49  M2 = standardTime.charAt(4);
50 
51  int h1 =  Character.getNumericValue(H1);
52  int h2 =  Character.getNumericValue(H2);
53  mins1 =  Character.getNumericValue(M1);
54  mins2 =  Character.getNumericValue(M2);
55 
56  hours = (h1*10)+h2;// will hold the hours
57 
58  if (hours>=12){//in a case where the time entered is after noon
59 
60  amPM=("PM");
61  hours = hours-12;//will set the number of hours to standard time
62  if (hours==0){
63  hours = 12;}
64  if (hours==12){
65  amPM = ("AM");}////due to midnight - set amPM to AM
66 
67  }//closes after noon if
68  else{
69  amPM=("AM");}
70 
71 
72 
73  traditionalTime=(hours+":"+mins1+""+mins2+" "+amPM+".");//makes the traditional time string complete
74 
75  }//closes converToTraditional method
76 
77 }
78