Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem 6 #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions src/main/java/io/zipcoder/AnotherWay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package io.zipcoder;

public class AnotherWay {

public String convert(String aTime) {

String time = "";

if (hasNoMinutes(aTime)) {
time += hours(aTime) + " Hundred Hours";
} else if (tenMinutes(aTime).equalsIgnoreCase("zero")) {
time += hours(aTime) + " Hundred " + tenMinutes(aTime) + minutes(aTime) + " Hours";
} else {
time += hours(aTime) + " Hundred and " + tenMinutes(aTime) + minutes(aTime) + " Hours";
}


return time;
}


// look out below!


public String splitHours(String aString) {
return aString.split(":")[0];
}

public String splitTens(String aTime) {
String afterColon = aTime.split(":")[1];
return afterColon.substring(0, 1);
}

public String splitMinutes(String aTime) {
String afterColon = aTime.split(":")[1];
return afterColon.substring(1, 2);
}

public String hours(String aString) {

String hoursString = splitHours(aString);
Integer hoursInt = Integer.parseInt(hoursString);
if (isPm(aString)) {
hoursInt += 12;
}
String hours = null;

for (Hour h : Hour.values()) {
if (h.getValue() == hoursInt) {
hours = h.toString();
}
}

if (hoursInt < 10) {
return "Zero " + hours.substring(0, 1) + hours.substring(1, hours.length()).toLowerCase();
} else {
return hours.substring(0, 1) + hours.substring(1, hours.length()).toLowerCase();
}
}

public String tenMinutes(String aTime) {

String tenMinutesString = splitTens(aTime);
Integer tensInt = Integer.parseInt(tenMinutesString);
String tens = "";

if (!hasNoMinutes(aTime) && !isTeen(aTime)) {

for (TenBasedMinute tbm : TenBasedMinute.values()) {
if (tbm.getValue() == tensInt) {
tens = tbm.toString();
}
}
}

if (tens.equalsIgnoreCase("")) {
return tens;
} else {
return tens.substring(0, 1) + tens.substring(1, tens.length()).toLowerCase();

}
}

public String minutes(String aTime) {
String minutesString = splitMinutes(aTime);
Integer minutesInt = Integer.parseInt(minutesString);
String minutes = "";

if (!hasNoMinutes(aTime) && !isTeen(aTime)) {

for (SingleMinute sm : SingleMinute.values()) {
if (sm.getValue() == minutesInt) {
minutes = sm.toString();
}
}
}

if (isTeen(aTime)) {
for (TeenMinute tm : TeenMinute.values()) {
if (tm.getValue() == minutesInt) {
minutes = tm.toString();
}
}
}

if (minutes.equalsIgnoreCase("")) {
return minutes;
} else if (isTeen(aTime)) {
return minutes.substring(0, 1) + minutes.substring(1, minutes.length()).toLowerCase();
} else {
return " " + minutes.substring(0, 1) + minutes.substring(1, minutes.length()).toLowerCase();
}
}


public boolean isPm(String aTime) {
if (aTime.contains("p")) {
return true;
} else {
return false;
}
}

public boolean isTeen(String aTime) {
if (aTime.charAt(aTime.length() - 4) == '1') {
return true;
} else {
return false;
}
}

public boolean hasNoMinutes(String aTime) {
if (aTime.charAt(aTime.length() - 4) == '0' && aTime.charAt(aTime.length() - 3) == '0') {
return true;
} else {
return false;
}
}


}
41 changes: 41 additions & 0 deletions src/main/java/io/zipcoder/Hour.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.zipcoder;

public enum Hour {

ONE(1),
TWO(2),
THREE(3),
FOUR(4),
FIVE(5),
SIX(6),
SEVEN(7),
EIGHT(8),
NINE(9),
TEN(10),
ELEVEN(11),
TWELVE(24),
THIRTEEN(13),
FOURTEEN(14),
FIFTEEN(15),
SIXTEEN(16),
SEVENTEEN(17),
EIGHTEEN(18),
NINETEEN(19),
TWENTY(20),
TWENTYONE(21),
TWENTYTWO(22),
TWENTYTHREE(23),
ZERO(12);

private final int value;

Hour(int value) {
this.value = value;
}

public int getValue() {
return value;
}


}
Loading