-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathProblem6.java
More file actions
65 lines (54 loc) · 2.39 KB
/
Problem6.java
File metadata and controls
65 lines (54 loc) · 2.39 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package io.zipcoder;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class Problem6 {
String[] words = {"Zero One", "Zero Two", "Zero Three", "Zero Four",
"Zero Five", "Zero Six", "Zero Seven", "Zero Eight", "Zero Nine",
"Ten", "Eleven", "Twelve", "Thirteen",
"Fourteen", "Fifteen", "Sixteen", "Seventeen",
"Eighteen", "Nineteen", "Twenty", "Twenty One",
"Twenty Two", "Twenty Three", "Twenty Four","Twenty Five", "Twenty Six",
"Twenty Seven", "Twenty Eight", "Twenty Nine", "Thirty", "Thirty One", "Thirty Two",
"Thirty Three", "Thirty Four", "Thirty Five", "Thirty Six", "Thirty Seven", "Thirty Eight",
"Thirty Nine", "Forty", "Forty One", "Forty Two", "Forty Three", "Forty Four", "Forty Five", "Forty Six",
"Forty Seven", "Forty Eight", "Forty Nine", "Fifty", "Fifty One", "Fifty Two", "Fifty Three", "Fifty Four",
"Fifty Five", "Fifty Six", "Fifty Seven", "Fifty Eight", "Fifty Nine", "Sixty"};
public String timeConverter(String inputTime){
DateFormat inputString= new SimpleDateFormat("hh:mmaa");
DateFormat outputString = new SimpleDateFormat("HH:mm");
try {
String date = outputString.format(inputString.parse(inputTime));
return date;
}catch (ParseException e) {
e.printStackTrace();
}
return null;
}
public String[] splitTime(String inputTime){
String[] timeIsSplit = inputTime.split(":");
return timeIsSplit;
}
public String convertIndexToWord(String input){
int inputAsNumber = Integer.parseInt(input);
String actualWord = words[inputAsNumber-1];
return actualWord;
}
public String formatWords(String hundreds, String Hours){
StringBuilder sb = new StringBuilder();
sb.append(hundreds);
sb.append(" ");
sb.append("Hundred and ");
sb.append(Hours);
sb.append(" ");
sb.append("Hours");
return sb.toString();
}
public String seeIfWholeThingWorks(String input){
String convert = timeConverter(input);
String[] split = splitTime(convert);
String indexOne = convertIndexToWord(split[0]);
String indexTwo = convertIndexToWord(split[1]);
return formatWords(indexOne, indexTwo);
}
}