Skip to content

Instantly share code, notes, and snippets.

@zeitan
Last active April 22, 2020 02:09
Show Gist options
  • Save zeitan/3a97247894aab832601b22572fc45c64 to your computer and use it in GitHub Desktop.
Save zeitan/3a97247894aab832601b22572fc45c64 to your computer and use it in GitHub Desktop.
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