-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeConverterApp.java
More file actions
49 lines (43 loc) · 1.83 KB
/
TimeConverterApp.java
File metadata and controls
49 lines (43 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package module6.exceptions_and_io.timeexception;
import java.util.Scanner;
/**
* TimeConverter
*/
public class TimeConverterApp {
protected static final Scanner scanner = new Scanner(System.in);
public static String inputString(String prompt) {
System.out.print(prompt);
return scanner.nextLine();
}
public static void main(String[] args) {
System.out.println(
"===================================================\n" +
"| |\n" +
"| 24-HOUR TIME CONVERTER APP |\n" +
"| by Mae Morella |\n" +
"| |\n" +
"===================================================");
for (int i = 0; ; i++) {
System.out.println();
String prompt = "Enter time in 24-hour notation" + (i > 0 ? " ('q' to exit)" : "") + ": ";
String input = inputString(prompt);
if (input.matches("[Qq]")) {
break;
}
try {
Time t = Time.parseTime(input);
System.out.println("That is the same as " + t.get12HourTime());
} catch (TimeFormatException e) {
System.err.println(e.getMessage());
}
}
System.out.println("\n"+
"===================================================\n" +
"| |\n" +
"| Thank you! The program will now exit. |\n" +
"| Have a nice day! |\n" +
"| |\n" +
"===================================================\n");
System.exit(0);
}
}