From 45f79edeab42c41456eb3d94236d56f4d17382db Mon Sep 17 00:00:00 2001 From: ahsonali Date: Mon, 16 Apr 2018 21:45:41 -0400 Subject: [PATCH 1/4] parsed only, more to do --- src/main/java/io/zipcoder/Problem6.java | 109 ++++++++++++ src/test/java/io/zipcoder/Problem6Test.java | 181 ++++++++++++++++++++ 2 files changed, 290 insertions(+) diff --git a/src/main/java/io/zipcoder/Problem6.java b/src/main/java/io/zipcoder/Problem6.java index 4ee4e64..9ab3f59 100644 --- a/src/main/java/io/zipcoder/Problem6.java +++ b/src/main/java/io/zipcoder/Problem6.java @@ -1,4 +1,113 @@ package io.zipcoder; public class Problem6 { + + private String militaryHour; + private String militaryMinute; + + private String[] hoursArray = {"Zero-zero", "Zero One Hundred ", "Zero Two Hundred ", "Zero Three Hundred ", + "Zero Four Hundred ", "Zero Five Hundred ", "Zero Six Hundred ", " Zero Seven Hundred ", + "Zero Eight Hundred ", "Zero Nine Hundred ", "Ten Hundred ", "Eleven Hundred ", + "Twelve Hundred ", "Thirteen Hundred ", "Fourteen Hundred ", "Fifteen Hundred ", + "Sixteen Hundred ", "Seventeen Hundred ", "Eighteen Hundred ", "Nineteen Hundred ", + "Twenty Hundred ", "Twenty One Hundred ", "Twenty Two Hundred ", "Twenty Three Hundred ", + "Twenty Four Hundred "}; + private String[] minutesArray = {"", "and One", "and Two", "and Three", "and Four", "and Five", "and Six", "and Seven", + "and Eight", "and Nine", "and Ten", "and Eleven", "and Twelve", "and Thirteen", + "and Fourteen", "and Fifteen", "and Sixteen", "and Seventeen", "and Eighteen", + "and Nineteen", "and Twenty", "and Twenty One", "and Twenty Two", "and Twenty Three", + "and Twenty Four", "and Twenty Five", "and Twenty Six", "and Twenty Seven", + "and Twenty Eight", "and Twenty Nine", "and Thirty", "and Thirty One", + "and Thirty One", "and Thirty Two", "and Thirty Three", "and Thirty Four", + "and Thirty Five", "and Thirty Six", "and Thirty Seven", "and Thirty Eight", + "and Thirty Nine", "and Fourty", "and Fourty One", "and Fourty Two", "and Fourty Three", + "and Fourty Four", "and Fourty Five", "and Fourty Six", "and Fourty Seven", + "and Fourty Eight", "and Fourty Nine", "and Fifty", "and Fifty One", "and Fifty Two", + "and Fifty Three", "and Fifty Four", "and Fifty Five", "and Fifty Six", "and Fifty Seven", + "and Fifty Eight", "and Fifty Nine", "zero-zero"}; + + public String[] splitTime(String timeInput) + { + String [] splitHourAndMinute = timeInput.split(":"); + return splitHourAndMinute; + } + + public Integer parseForHour(String timeInput) + { + String [] hour = splitTime(timeInput); + Integer intHour = Integer.parseInt(hour[0]); + + if(hour[1].contains("p") || hour[1].contains("P")) + { + return intHour += 12; + } + else { + return intHour; + } + } + + public Integer parseForMinute(String timeInput) + { + String [] minute = splitTime(timeInput); + String minutePortion = minute[1]; + + //Using Stringbuilder to append minute without the am or pm + StringBuilder noAmOrPm = new StringBuilder(); + noAmOrPm.append(minutePortion.charAt(0)); + noAmOrPm.append(minutePortion.charAt(1)); + + //StringBuilder to String + String minuteToString = noAmOrPm.toString(); + + //String parsed to Integer + Integer minuteOnly = Integer.parseInt(minuteToString); + + return minuteOnly; + } + + + + } + + + + + + + + + + + + + + + + + + + + + + + + + + + +// this.hour = hour; +// this.amOrPm = amOrPm; + + +// public static String timeToString(String digitalTime){ +// +// +// +// return null; +// } + +//private static int hour; +//private String minute +//private final String timeColon = ":" +//private static String amOrPm; \ No newline at end of file diff --git a/src/test/java/io/zipcoder/Problem6Test.java b/src/test/java/io/zipcoder/Problem6Test.java index d262e88..1967c14 100644 --- a/src/test/java/io/zipcoder/Problem6Test.java +++ b/src/test/java/io/zipcoder/Problem6Test.java @@ -1,4 +1,185 @@ package io.zipcoder; +import org.junit.Assert; +import org.junit.Test; + public class Problem6Test { + + @Test + public void testSplitTime() + { + //Given + Problem6 problem6 = new Problem6(); + String timeInput = "1:30pm"; + String hour = "1"; + String minute = "30"; + String [] expected = {"1", "30pm"}; + + //When + String [] actual = problem6.splitTime(timeInput); + + //Then + Assert.assertEquals(expected, actual); + + + } + + @Test + public void testParseForHour1() + { + //Given + Problem6 problem6 = new Problem6(); + String timeInput = "1:30pm"; + Integer expected = 13; + + //When + Integer actual = problem6.parseForHour(timeInput); + + //Then + Assert.assertEquals(expected, actual); + + + } + + @Test + public void testParseForHour2() + { + //Given + Problem6 problem6 = new Problem6(); + String timeInput = "2:30pm"; + Integer expected = 14; + + //When + Integer actual = problem6.parseForHour(timeInput); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testParseForHour3() + { + //Given + Problem6 problem6 = new Problem6(); + String timeInput = "3:30pm"; + Integer expected = 15; + + //When + Integer actual = problem6.parseForHour(timeInput); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testParseForHour4() + { + //Given + Problem6 problem6 = new Problem6(); + String timeInput = "7:00pm"; + Integer expected = 19; + + //When + Integer actual = problem6.parseForHour(timeInput); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testParseForHour5() + { + //Given + Problem6 problem6 = new Problem6(); + String timeInput = "1:30am"; + Integer expected = 1; + + //When + Integer actual = problem6.parseForHour(timeInput); + + //Then + Assert.assertEquals(expected, actual); + + + } + + @Test + public void testParseForHour6() + { + //Given + Problem6 problem6 = new Problem6(); + String timeInput = "2:30am"; + Integer expected = 2; + + //When + Integer actual = problem6.parseForHour(timeInput); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testParseForHour7() + { + //Given + Problem6 problem6 = new Problem6(); + String timeInput = "3:30am"; + Integer expected = 3; + + //When + Integer actual = problem6.parseForHour(timeInput); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testParseForHour8() + { + //Given + Problem6 problem6 = new Problem6(); + String timeInput = "7:00am"; + Integer expected = 7; + + //When + Integer actual = problem6.parseForHour(timeInput); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testParseForMinute1() + { + //Given + Problem6 problem6 = new Problem6(); + String timeInput = "4:45am"; + Integer expected = 45; + + //When + Integer actual = problem6.parseForMinute(timeInput); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testParseForMinute2() + { + //Given + Problem6 problem6 = new Problem6(); + String timeInput = "4:03am"; + Integer expected = 03; + + //When + Integer actual = problem6.parseForMinute(timeInput); + + //Then + Assert.assertEquals(expected, actual); + } + + + + + } From fd1dd0c2eb87ddfe69aecb39a1910596e84ff4e8 Mon Sep 17 00:00:00 2001 From: ahsonali Date: Mon, 16 Apr 2018 22:11:51 -0400 Subject: [PATCH 2/4] put my hoursArray to use --- src/main/java/io/zipcoder/Problem6.java | 13 +++++++++ src/test/java/io/zipcoder/Problem6Test.java | 32 +++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/main/java/io/zipcoder/Problem6.java b/src/main/java/io/zipcoder/Problem6.java index 9ab3f59..51262ee 100644 --- a/src/main/java/io/zipcoder/Problem6.java +++ b/src/main/java/io/zipcoder/Problem6.java @@ -65,6 +65,19 @@ public Integer parseForMinute(String timeInput) return minuteOnly; } + public String getMilitaryHour(Integer hour) + { + militaryHour = hoursArray[hour]; + return militaryHour; + } + +// public String getMilitaryMinute() +// { +// +// } + + + diff --git a/src/test/java/io/zipcoder/Problem6Test.java b/src/test/java/io/zipcoder/Problem6Test.java index 1967c14..b63e07e 100644 --- a/src/test/java/io/zipcoder/Problem6Test.java +++ b/src/test/java/io/zipcoder/Problem6Test.java @@ -161,6 +161,8 @@ public void testParseForMinute1() //Then Assert.assertEquals(expected, actual); + + } @Test @@ -174,10 +176,40 @@ public void testParseForMinute2() //When Integer actual = problem6.parseForMinute(timeInput); + //Then + Assert.assertEquals(expected, actual); + + } + + @Test + public void testgetMilitaryHour1() + { + //Given + Problem6 problem6 = new Problem6(); + Integer hour = 16; + String expected = "Sixteen Hundred "; + + //When + String actual = problem6.getMilitaryHour(hour); + //Then Assert.assertEquals(expected, actual); } + @Test + public void testgetMilitaryHour2() + { + //Given + Problem6 problem6 = new Problem6(); + Integer hour = 1; + String expected = "Zero One Hundred "; + + //When + String actual = problem6.getMilitaryHour(hour); + + //Then + Assert.assertEquals(expected, actual); + } From 1a0a67fc160da67288b7b44acb2d3fc2e0124535 Mon Sep 17 00:00:00 2001 From: ahsonali Date: Mon, 16 Apr 2018 22:56:25 -0400 Subject: [PATCH 3/4] one more method, with its test to add --- src/main/java/io/zipcoder/Problem6.java | 44 +++++--------- src/test/java/io/zipcoder/Problem6Test.java | 63 +++++++++++++++++++++ 2 files changed, 76 insertions(+), 31 deletions(-) diff --git a/src/main/java/io/zipcoder/Problem6.java b/src/main/java/io/zipcoder/Problem6.java index 51262ee..661a5b0 100644 --- a/src/main/java/io/zipcoder/Problem6.java +++ b/src/main/java/io/zipcoder/Problem6.java @@ -5,26 +5,19 @@ public class Problem6 { private String militaryHour; private String militaryMinute; - private String[] hoursArray = {"Zero-zero", "Zero One Hundred ", "Zero Two Hundred ", "Zero Three Hundred ", + private String[] hoursArray = {"Zero Hundred ", "Zero One Hundred ", "Zero Two Hundred ", "Zero Three Hundred ", "Zero Four Hundred ", "Zero Five Hundred ", "Zero Six Hundred ", " Zero Seven Hundred ", "Zero Eight Hundred ", "Zero Nine Hundred ", "Ten Hundred ", "Eleven Hundred ", "Twelve Hundred ", "Thirteen Hundred ", "Fourteen Hundred ", "Fifteen Hundred ", "Sixteen Hundred ", "Seventeen Hundred ", "Eighteen Hundred ", "Nineteen Hundred ", "Twenty Hundred ", "Twenty One Hundred ", "Twenty Two Hundred ", "Twenty Three Hundred ", "Twenty Four Hundred "}; - private String[] minutesArray = {"", "and One", "and Two", "and Three", "and Four", "and Five", "and Six", "and Seven", - "and Eight", "and Nine", "and Ten", "and Eleven", "and Twelve", "and Thirteen", - "and Fourteen", "and Fifteen", "and Sixteen", "and Seventeen", "and Eighteen", - "and Nineteen", "and Twenty", "and Twenty One", "and Twenty Two", "and Twenty Three", - "and Twenty Four", "and Twenty Five", "and Twenty Six", "and Twenty Seven", - "and Twenty Eight", "and Twenty Nine", "and Thirty", "and Thirty One", - "and Thirty One", "and Thirty Two", "and Thirty Three", "and Thirty Four", - "and Thirty Five", "and Thirty Six", "and Thirty Seven", "and Thirty Eight", - "and Thirty Nine", "and Fourty", "and Fourty One", "and Fourty Two", "and Fourty Three", - "and Fourty Four", "and Fourty Five", "and Fourty Six", "and Fourty Seven", - "and Fourty Eight", "and Fourty Nine", "and Fifty", "and Fifty One", "and Fifty Two", - "and Fifty Three", "and Fifty Four", "and Fifty Five", "and Fifty Six", "and Fifty Seven", - "and Fifty Eight", "and Fifty Nine", "zero-zero"}; + private String[] minutesArray = {"", "and One", "and Two", "and Three", "and Four", "and Five", "and Six", "and Seven", "and Eight", "and Nine", "and Ten", + "and Eleven", "and Twelve", "and Thirteen", "and Fourteen", "and Fifteen", "and Sixteen", "and Seventeen", "and Eighteen", "and Nineteen", "and Twenty", + "and Twenty One", "and Twenty Two", "and Twenty Three", "and Twenty Four", "and Twenty Five", "and Twenty Six", "and Twenty Seven", "and Twenty Eight", "and Twenty Nine", "and Thirty", + "and Thirty One", "and Thirty Two", "and Thirty Three", "and Thirty Four", "and Thirty Five", "and Thirty Six", "and Thirty Seven", "and Thirty Eight","and Thirty Nine","and Fourty", + "and Fourty One", "and Fourty Two", "and Fourty Three", "and Fourty Four", "and Fourty Five", "and Fourty Six", "and Fourty Seven", "and Fourty Eight", "and Fourty Nine", "and Fifty", + "and Fifty One", "and Fifty Two", "and Fifty Three", "and Fifty Four", "and Fifty Five", "and Fifty Six", "and Fifty Seven", "and Fifty Eight", "and Fifty Nine"}; public String[] splitTime(String timeInput) { @@ -71,20 +64,21 @@ public String getMilitaryHour(Integer hour) return militaryHour; } -// public String getMilitaryMinute() -// { -// -// } + public String getMilitaryMinute(Integer minute) + { + militaryMinute = minutesArray[minute]; + return militaryMinute; + } -} +} @@ -109,18 +103,6 @@ public String getMilitaryHour(Integer hour) -// this.hour = hour; -// this.amOrPm = amOrPm; -// public static String timeToString(String digitalTime){ -// -// -// -// return null; -// } -//private static int hour; -//private String minute -//private final String timeColon = ":" -//private static String amOrPm; \ No newline at end of file diff --git a/src/test/java/io/zipcoder/Problem6Test.java b/src/test/java/io/zipcoder/Problem6Test.java index b63e07e..fd18633 100644 --- a/src/test/java/io/zipcoder/Problem6Test.java +++ b/src/test/java/io/zipcoder/Problem6Test.java @@ -211,6 +211,69 @@ public void testgetMilitaryHour2() Assert.assertEquals(expected, actual); } + @Test + public void testGetMilitaryMinute1() + { + //Given + Problem6 problem6 = new Problem6(); + Integer minute = 00; + String expected = ""; + + //When + String actual = problem6.getMilitaryMinute(minute); + + //Then + Assert.assertEquals(expected, actual); + + + } + + @Test + public void testGetMilitaryMinute2() + { + //Given + Problem6 problem6 = new Problem6(); + Integer minute = 01; + String expected = "and One"; + + //When + String actual = problem6.getMilitaryMinute(minute); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetMilitaryTime3() + { + //Given + Problem6 problem6 = new Problem6(); + Integer minute = 02; + String expected = "and Two"; + + //When + String actual = problem6.getMilitaryMinute(minute); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetMilitaryTime4() + { + //Given + Problem6 problem6 = new Problem6(); + Integer minute = 59; + String expected = "and Fifty Nine"; + + //When + String actual = problem6.getMilitaryMinute(minute); + + //Then + Assert.assertEquals(expected, actual); + } + + From 60ef8a27e928d478898a404f0232a05a770d14b2 Mon Sep 17 00:00:00 2001 From: ahsonali Date: Mon, 16 Apr 2018 23:24:04 -0400 Subject: [PATCH 4/4] may or may not need to modify one more method --- src/main/java/io/zipcoder/Problem6.java | 72 +++++++++++---------- src/test/java/io/zipcoder/Problem6Test.java | 2 + 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/main/java/io/zipcoder/Problem6.java b/src/main/java/io/zipcoder/Problem6.java index 661a5b0..db99bf2 100644 --- a/src/main/java/io/zipcoder/Problem6.java +++ b/src/main/java/io/zipcoder/Problem6.java @@ -6,42 +6,37 @@ public class Problem6 { private String militaryMinute; private String[] hoursArray = {"Zero Hundred ", "Zero One Hundred ", "Zero Two Hundred ", "Zero Three Hundred ", - "Zero Four Hundred ", "Zero Five Hundred ", "Zero Six Hundred ", " Zero Seven Hundred ", - "Zero Eight Hundred ", "Zero Nine Hundred ", "Ten Hundred ", "Eleven Hundred ", - "Twelve Hundred ", "Thirteen Hundred ", "Fourteen Hundred ", "Fifteen Hundred ", - "Sixteen Hundred ", "Seventeen Hundred ", "Eighteen Hundred ", "Nineteen Hundred ", - "Twenty Hundred ", "Twenty One Hundred ", "Twenty Two Hundred ", "Twenty Three Hundred ", - "Twenty Four Hundred "}; + "Zero Four Hundred ", "Zero Five Hundred ", "Zero Six Hundred ", " Zero Seven Hundred ", + "Zero Eight Hundred ", "Zero Nine Hundred ", "Ten Hundred ", "Eleven Hundred ", + "Twelve Hundred ", "Thirteen Hundred ", "Fourteen Hundred ", "Fifteen Hundred ", + "Sixteen Hundred ", "Seventeen Hundred ", "Eighteen Hundred ", "Nineteen Hundred ", + "Twenty Hundred ", "Twenty One Hundred ", "Twenty Two Hundred ", "Twenty Three Hundred ", + "Twenty Four Hundred "}; private String[] minutesArray = {"", "and One", "and Two", "and Three", "and Four", "and Five", "and Six", "and Seven", "and Eight", "and Nine", "and Ten", - "and Eleven", "and Twelve", "and Thirteen", "and Fourteen", "and Fifteen", "and Sixteen", "and Seventeen", "and Eighteen", "and Nineteen", "and Twenty", - "and Twenty One", "and Twenty Two", "and Twenty Three", "and Twenty Four", "and Twenty Five", "and Twenty Six", "and Twenty Seven", "and Twenty Eight", "and Twenty Nine", "and Thirty", - "and Thirty One", "and Thirty Two", "and Thirty Three", "and Thirty Four", "and Thirty Five", "and Thirty Six", "and Thirty Seven", "and Thirty Eight","and Thirty Nine","and Fourty", - "and Fourty One", "and Fourty Two", "and Fourty Three", "and Fourty Four", "and Fourty Five", "and Fourty Six", "and Fourty Seven", "and Fourty Eight", "and Fourty Nine", "and Fifty", - "and Fifty One", "and Fifty Two", "and Fifty Three", "and Fifty Four", "and Fifty Five", "and Fifty Six", "and Fifty Seven", "and Fifty Eight", "and Fifty Nine"}; - - public String[] splitTime(String timeInput) - { - String [] splitHourAndMinute = timeInput.split(":"); + "and Eleven", "and Twelve", "and Thirteen", "and Fourteen", "and Fifteen", "and Sixteen", "and Seventeen", "and Eighteen", "and Nineteen", "and Twenty", + "and Twenty One", "and Twenty Two", "and Twenty Three", "and Twenty Four", "and Twenty Five", "and Twenty Six", "and Twenty Seven", "and Twenty Eight", "and Twenty Nine", "and Thirty", + "and Thirty One", "and Thirty Two", "and Thirty Three", "and Thirty Four", "and Thirty Five", "and Thirty Six", "and Thirty Seven", "and Thirty Eight", "and Thirty Nine", "and Fourty", + "and Fourty One", "and Fourty Two", "and Fourty Three", "and Fourty Four", "and Fourty Five", "and Fourty Six", "and Fourty Seven", "and Fourty Eight", "and Fourty Nine", "and Fifty", + "and Fifty One", "and Fifty Two", "and Fifty Three", "and Fifty Four", "and Fifty Five", "and Fifty Six", "and Fifty Seven", "and Fifty Eight", "and Fifty Nine"}; + + public String[] splitTime(String timeInput) { + String[] splitHourAndMinute = timeInput.split(":"); return splitHourAndMinute; } - public Integer parseForHour(String timeInput) - { - String [] hour = splitTime(timeInput); + public Integer parseForHour(String timeInput) { + String[] hour = splitTime(timeInput); Integer intHour = Integer.parseInt(hour[0]); - if(hour[1].contains("p") || hour[1].contains("P")) - { + if (hour[1].contains("p") || hour[1].contains("P")) { return intHour += 12; - } - else { + } else { return intHour; } } - public Integer parseForMinute(String timeInput) - { - String [] minute = splitTime(timeInput); + public Integer parseForMinute(String timeInput) { + String[] minute = splitTime(timeInput); String minutePortion = minute[1]; //Using Stringbuilder to append minute without the am or pm @@ -58,25 +53,34 @@ public Integer parseForMinute(String timeInput) return minuteOnly; } - public String getMilitaryHour(Integer hour) - { + public String getMilitaryHour(Integer hour) { militaryHour = hoursArray[hour]; return militaryHour; } - public String getMilitaryMinute(Integer minute) - { + public String getMilitaryMinute(Integer minute) { militaryMinute = minutesArray[minute]; return militaryMinute; } + //Testing this method in main method below + public String getFullMilitaryTime(String hour, String minute) { + return militaryHour + "Hundred " + militaryMinute + " Hours"; + } - - - - - + public static void main(String[] args) + { + String timeInput = "1:30pm"; + String militaryHour; + String militaryMinutes; + + Problem6 problem6 = new Problem6(); + militaryHour = problem6.getMilitaryHour(problem6.parseForHour(timeInput)); + militaryMinutes = problem6.getMilitaryMinute(problem6.parseForMinute(timeInput)); + problem6.getFullMilitaryTime(militaryHour, militaryMinutes); + System.out.println(problem6.getFullMilitaryTime(militaryHour, militaryMinutes)); + } } diff --git a/src/test/java/io/zipcoder/Problem6Test.java b/src/test/java/io/zipcoder/Problem6Test.java index fd18633..39136fa 100644 --- a/src/test/java/io/zipcoder/Problem6Test.java +++ b/src/test/java/io/zipcoder/Problem6Test.java @@ -277,4 +277,6 @@ public void testGetMilitaryTime4() + + }