diff --git a/pom.xml b/pom.xml index 5fd8efa..7b5cfe2 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,18 @@ io.zipcoder InterviewProblem5 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + diff --git a/src/main/java/io/zipcoder/MilitarConvention.java b/src/main/java/io/zipcoder/MilitarConvention.java new file mode 100644 index 0000000..ff30bd9 --- /dev/null +++ b/src/main/java/io/zipcoder/MilitarConvention.java @@ -0,0 +1,71 @@ +package io.zipcoder; + +public class MilitarConvention { + + + + + public String amTime(Integer value) { + + final String[] units = {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"}; + final String[] tens = {"", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty"}; + + if (value == 100) { + return "Zero One Hundred hours"; + } + if (value < 100) { + return (units[0] + " " + units[0] + " " + tens[value % 10] + " " + units[value % 10]); + } else if (value < 1000 && value > 100) { + + if((value % 100) < 20){ + return units[0] + " " + units[value / 100] + " " + "hundred and " + units[(value % 100)]; + } + + return units[0] + " " + units[value / 100] + " " + "hundred and " + tens[(value % 100) / 10] + " " + units[value % 100 / 10]; + + } else if (value > 1000 && value < 2359) { + return units[value / 100] + " " + "hundred" + " " + tens[(value % 100) / 10] + " " + units[(value % 1000) % 20]; + } + return null; + } + + + public String pmTime(Integer number){ + + Integer value = pmConverted (number); + + String[] units = {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"}; + String[] tens = {"", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty"}; + + if (value == 1200) { + return "Zero Zero Zero Zero"; + } +//1331 + if (value > 1300 && value < 1400) { + + if(value % 10 != 0){ + return ( units[value / 100] + " hundred " + tens[(value%1000) % 100 ] + " " + units[((value % 1000) % (100) % (10))]); + } + + } else if (value < 1000 && value > 100) { + + if((value % 1000) > 19){ + return units[0] + " " + units[value / 100] + " " + "hundred " + tens[(value % 100) / 10] + " " + units[value % 100 / 10]; + } + } else if (value > 1000 && value < 2359) { + return units[value / 100] + " " + "hundred" + " " + tens[(value % 100) / 10] + " " + units[(value % 1000) % 20]; + } + return null; + } + + + public int pmConverted(Integer number){ + + Integer value = ((number/100) + 12) * 100 + (number % 100); + + return value; + } + + +} + diff --git a/src/main/java/io/zipcoder/Problem6.java b/src/main/java/io/zipcoder/Problem6.java index 4ee4e64..af40329 100644 --- a/src/main/java/io/zipcoder/Problem6.java +++ b/src/main/java/io/zipcoder/Problem6.java @@ -1,4 +1,74 @@ package io.zipcoder; + +import java.util.Scanner; + public class Problem6 { + +// AM FEATURES WORKING + // PM FEATURES SOON + + static MilitarConvention convention = new MilitarConvention (); + + // WORKING STILL ON PM FEATURES + + public static void main(String[] args) { + + int var = 1330 / 100; + System.out.println (var); + + Problem6 problem6 = new Problem6 (); + + System.out.println ("Enter standard time..."); + + String timeEntered = problem6.scanner (); + + if(problem6.getPmOrAm (timeEntered).equalsIgnoreCase ("am")){ + String amTimeResult = convention.amTime (problem6.cleanNumber (timeEntered)); + System.out.println (amTimeResult + " Hours"); + + }else if(problem6.getPmOrAm (timeEntered).equalsIgnoreCase ("pm")){ + String pmTimeResult = convention.pmTime (problem6.cleanNumber (timeEntered)); + System.out.println (pmTimeResult + " Hours"); + } + + } + + public String getPmOrAm(String userInput) { + + return userInput.substring (userInput.length () - 2, userInput.length ()); + } + + public String getNumberWithOutamOrPm(String userInput) { + + return userInput.substring (0, userInput.length () - 2); + } + + + public String removeSemicolon(String userInput) { + + String trim = userInput.trim (); + + return trim.replace (":", ""); + } + + public int numberToInt(String str) { + + return Integer.parseInt (str); + } + + public int cleanNumber(String str) { + + return numberToInt (removeSemicolon (getNumberWithOutamOrPm (str))); + + } + + public String scanner() { + + Scanner scanner = new Scanner (System.in); + + return scanner.next (); + } } + + diff --git a/src/test/java/io/zipcoder/MilitarConventionTest.java b/src/test/java/io/zipcoder/MilitarConventionTest.java new file mode 100644 index 0000000..280ce20 --- /dev/null +++ b/src/test/java/io/zipcoder/MilitarConventionTest.java @@ -0,0 +1,19 @@ +package io.zipcoder; + +import org.junit.Assert; +import org.junit.Test; + + + +public class MilitarConventionTest { + + MilitarConvention mc = new MilitarConvention (); + + @Test + public void pmConvertedTest(){ + + int expected = 1330; + int actual = mc.pmConverted (130); + Assert.assertEquals (expected, actual); + } +} diff --git a/src/test/java/io/zipcoder/Problem6Test.java b/src/test/java/io/zipcoder/Problem6Test.java index d262e88..aa50ef7 100644 --- a/src/test/java/io/zipcoder/Problem6Test.java +++ b/src/test/java/io/zipcoder/Problem6Test.java @@ -1,4 +1,52 @@ package io.zipcoder; +import org.junit.Assert; +import org.junit.Test; + public class Problem6Test { + +Problem6 problem6 = new Problem6(); + @Test + public void getPmOrAmTest(){ + + String expected = "am"; + String actual = problem6.getPmOrAm ("1:30am"); + Assert.assertEquals (expected, actual); + } + + @Test + public void getNumberWithOutamOrPm(){ + + String expected = "1:30"; + String actual = problem6.getNumberWithOutamOrPm ("1:30am"); + Assert.assertEquals (expected, actual); + } + + @Test + public void removeSemicolonTest(){ + + String expected = "130"; + String actual = problem6.removeSemicolon (problem6.getNumberWithOutamOrPm ("1:30am")); + Assert.assertEquals (expected, actual); + } + + @Test + public void numberToIntTest(){ + + int expected = 130; + int actual = problem6.numberToInt ("130"); + Assert.assertEquals (expected, actual); + } + + @Test + public void cleanNumberTest(){ + + int expected = 130; + int actual = problem6.cleanNumber ("1:30pm"); + Assert.assertEquals (expected, actual); + } + + + + }