diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..39d929e
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..63e9001
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..712ab9d
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__joda_time_joda_time_2_9_7.xml b/.idea/libraries/Maven__joda_time_joda_time_2_9_7.xml
new file mode 100644
index 0000000..984d50b
--- /dev/null
+++ b/.idea/libraries/Maven__joda_time_joda_time_2_9_7.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml
new file mode 100644
index 0000000..a82457d
--- /dev/null
+++ b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_4_2.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_4_2.xml
new file mode 100644
index 0000000..5a695a5
--- /dev/null
+++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_4_2.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_4_2.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_4_2.xml
new file mode 100644
index 0000000..688205a
--- /dev/null
+++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_4_2.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_4_2.xml b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_4_2.xml
new file mode 100644
index 0000000..1507a25
--- /dev/null
+++ b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_4_2.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_4_2.xml b/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_4_2.xml
new file mode 100644
index 0000000..080af65
--- /dev/null
+++ b/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_4_2.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_opentest4j_opentest4j_1_1_1.xml b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_1_1.xml
new file mode 100644
index 0000000..70277df
--- /dev/null
+++ b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_1_1.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..25daa30
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..958c2f6
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..3c21e88
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1621546576400
+
+
+ 1621546576400
+
+
+
+
\ No newline at end of file
diff --git a/java-interview.iml b/java-interview.iml
new file mode 100644
index 0000000..0031144
--- /dev/null
+++ b/java-interview.iml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/github/archarithms/App.java b/src/main/java/com/github/archarithms/App.java
index dcb6723..550f5c9 100644
--- a/src/main/java/com/github/archarithms/App.java
+++ b/src/main/java/com/github/archarithms/App.java
@@ -1,15 +1,46 @@
package com.github.archarithms;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
public class App
{
- public static String convertToTitleCase(final String inpStr)
- {
- return inpStr;
+ public static String convertToTitleCase(final String inpStr) throws Exception {
+ if (inpStr == null) {
+ throw new Exception();
+ }
+ StringBuilder sb = new StringBuilder();
+ // Split up the string and remove all of the garbage characters
+ String[] splitInput = inpStr.split("]|-|_|\\[|/");
+ for (int i = 0; i < splitInput.length; i++) {
+ // Set the entire string to lowercase
+ String s = splitInput[i].toLowerCase();
+ // check to see if the string contains anything
+ if (s.length() > 0) {
+ // Set the first letter to Uppercase if possible
+ String first = s.substring(0, 1).toUpperCase();
+ String temp = s.substring(1);
+ // Concat the 2 strings and append it to the StringBuilder
+ sb.append(first.concat(temp));
+ }
+ // Append a space to the StringBuilder this isn't the last string
+ if (i < splitInput.length - 1) {
+ sb.append(" ");
+ }
+ }
+ return sb.toString();
}
- public static String convertUnixToDateString(final Long inpUnixSeconds)
- {
- return String.valueOf(inpUnixSeconds);
+ public static String convertUnixToDateString(final Long inpUnixSeconds) throws Exception {
+ if (inpUnixSeconds == null) {
+ throw new Exception();
+ }
+ // Convert to milliseconds
+ Long millis = inpUnixSeconds * 1000;
+ // Using DateFormat with a Date to make get the correct format
+ Date date = new Date(millis);
+ DateFormat format = new SimpleDateFormat("MMMMMMMMM d, y");
+ return format.format(date);
}
}
diff --git a/src/test/java/com/github/archarithms/test/DateStringTests.java b/src/test/java/com/github/archarithms/test/DateStringTests.java
index 04e9943..1f45eed 100644
--- a/src/test/java/com/github/archarithms/test/DateStringTests.java
+++ b/src/test/java/com/github/archarithms/test/DateStringTests.java
@@ -21,7 +21,7 @@ public class DateStringTests
* Test the testConvertUnixToDateString method
*/
@Test
- public void testConvertUnixToDateString() {
+ public void testConvertUnixToDateString() throws Exception {
String testStr = "July 4, 2017";
assertTrue(testStr.equals(App.convertUnixToDateString(1499144400L)));
}
@@ -33,4 +33,13 @@ public void testConvertUnixToDateString() {
public void testNullCase() {
assertThrows(Exception.class, () -> App.convertUnixToDateString(null));
}
+
+ /**
+ * Test the testMyBirthday method
+ */
+ @Test
+ public void testMyBirthday() throws Exception {
+ String testStr = "August 14, 1998";
+ assertTrue(testStr.equals(App.convertUnixToDateString(903114000L)));
+ }
}
diff --git a/src/test/java/com/github/archarithms/test/TitleCaseTests.java b/src/test/java/com/github/archarithms/test/TitleCaseTests.java
index bd3bb2d..674b2af 100644
--- a/src/test/java/com/github/archarithms/test/TitleCaseTests.java
+++ b/src/test/java/com/github/archarithms/test/TitleCaseTests.java
@@ -1,11 +1,13 @@
package com.github.archarithms.test;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
import org.junit.jupiter.api.Test;
import com.github.archarithms.App;
+import java.text.ParseException;
+
+import static org.junit.jupiter.api.Assertions.*;
+
/**
* TitleCaseTests unit tests for simple App.
*/
@@ -20,7 +22,7 @@ public class TitleCaseTests
* Test the testConvertToTitleCase method
*/
@Test
- public void testConvertToTitleCase() {
+ public void testConvertToTitleCase() throws Exception {
String testStr = "Title Case";
assertTrue(testStr.equals(App.convertToTitleCase("TITLE_CASE")));
}
@@ -29,7 +31,7 @@ public void testConvertToTitleCase() {
* Test the testNumbers method
*/
@Test
- public void testNumbers() {
+ public void testNumbers() throws Exception {
String testStr = "Number 3";
assertTrue(testStr.equals(App.convertToTitleCase("NUMBER_3")));
}
@@ -38,8 +40,25 @@ public void testNumbers() {
* Test the testOtherChars method
*/
@Test
- public void testOtherChars() {
+ public void testOtherChars() throws Exception {
String testStr = "Truth Track";
assertTrue(testStr.equals(App.convertToTitleCase("TRUTH-TRACK")));
}
+
+ /**
+ * Test the testMultipleChars method
+ */
+ @Test
+ public void testMultipleChars() throws Exception {
+ String testStr = "Case Three Extra Chars";
+ assertTrue(testStr.equals(App.convertToTitleCase("CASE-THREE_extra[chars]///")));
+ }
+
+ /**
+ * Test the testNullString method
+ */
+ @Test
+ public void testNullString() {
+ assertThrows(Exception.class, () -> App.convertToTitleCase(null));
+ }
}