Last active
April 22, 2020 02:09
-
-
Save zeitan/3a97247894aab832601b22572fc45c64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static String buildProducts(String parts) { | |
int acumA = 0; | |
int acumB = 0; | |
int acumC = 0; | |
int acumD = 0; | |
int acumE = 0; | |
for (int i = 0; i < parts.length(); i++) { | |
switch (parts.charAt(i)) { | |
case 'a' : ++acumA; | |
break; | |
case 'b' : ++acumB; | |
break; | |
case 'c' : ++acumC; | |
break; | |
case 'd' : ++acumD; | |
break; | |
case 'e' : ++acumE; | |
break; | |
} | |
} | |
return "{\"Shelf\" :" + acumA + ", \"Stool\" : " + countProductComplete(acumB, acumC, 3) + ", \"Table\" : " + countProductComplete(acumD, acumE, 4) + "}"; | |
} | |
private static int countProductComplete(int partA, int partB, int minPiecesPartB) { | |
if (partA >= 1 && partB >= minPiecesPartB ) { | |
int maxPiecesPartB = partA * minPiecesPartB; | |
return (partB >= maxPiecesPartB ) ? partA : partB / minPiecesPartB; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment