1 import java.io.*;
2
3 public class Main {
4
5 static String amPM;
6 static String traditionalTime;
7 static int mins1, mins2, hours;
8
9 public static void main(String[] args) throws IOException {
10
11 BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
12
13 int tryAgain=1;
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();
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();
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());
39 }while(tryAgain==1);
40
41 }
42
43 public static void convertToTraditional(String standardTime){
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;
57
58 if (hours>=12){
59
60 amPM=("PM");
61 hours = hours-12;
62 if (hours==0){
63 hours = 12;}
64 if (hours==12){
65 amPM = ("AM");}
66
67 }
68 else{
69 amPM=("AM");}
70
71
72
73 traditionalTime=(hours+":"+mins1+""+mins2+" "+amPM+".");
74
75 }
76
77 }
78