- show progress to next drinking interval
- show minutes until next drinking interval
This commit is contained in:
@@ -19,6 +19,7 @@ public class DrinkingBar {
|
|||||||
private static final int MINUTES_BEFORE_PAUSE = 4 * MINS_PER_HOUR + MINS_PER_HALF_HOUR;
|
private static final int MINUTES_BEFORE_PAUSE = 4 * MINS_PER_HOUR + MINS_PER_HALF_HOUR;
|
||||||
private static final int MINUTES_WITH_PAUSE = 6 * MINS_PER_HOUR;
|
private static final int MINUTES_WITH_PAUSE = 6 * MINS_PER_HOUR;
|
||||||
private static final DecimalFormat LITER_FORMAT = new DecimalFormat("0.00");
|
private static final DecimalFormat LITER_FORMAT = new DecimalFormat("0.00");
|
||||||
|
private static final DecimalFormat PERCENTAGE_FORMAT = new DecimalFormat("00.00");
|
||||||
private static final BigDecimal MINS_PER_HOUR_BD = BigDecimal.valueOf(MINS_PER_HOUR);
|
private static final BigDecimal MINS_PER_HOUR_BD = BigDecimal.valueOf(MINS_PER_HOUR);
|
||||||
private static final MathContext MC_INTEGER = new MathContext(1, RoundingMode.HALF_EVEN);
|
private static final MathContext MC_INTEGER = new MathContext(1, RoundingMode.HALF_EVEN);
|
||||||
|
|
||||||
@@ -36,7 +37,10 @@ public class DrinkingBar {
|
|||||||
if (passedMinutes <= MINUTES_BEFORE_PAUSE || passedMinutes > MINUTES_WITH_PAUSE) {
|
if (passedMinutes <= MINUTES_BEFORE_PAUSE || passedMinutes > MINUTES_WITH_PAUSE) {
|
||||||
double currentLitres = 2.0 / totalMinutes * passedMinutes + 0.25;
|
double currentLitres = 2.0 / totalMinutes * passedMinutes + 0.25;
|
||||||
double printedLitres = currentLitres - (currentLitres % 0.25);
|
double printedLitres = currentLitres - (currentLitres % 0.25);
|
||||||
System.out.print("\rAktuelles Volumen: " + LITER_FORMAT.format(printedLitres) + "L");
|
double currentProgressToNextStep = 100 / 0.25 * (currentLitres - printedLitres);
|
||||||
|
long minutesToNextStep = getMinutesToNextStep(currentLitres, totalMinutes);
|
||||||
|
System.out.print("\rAktuelles Volumen: " + LITER_FORMAT.format(printedLitres) + "L - "
|
||||||
|
+ PERCENTAGE_FORMAT.format(currentProgressToNextStep) + "% - " + minutesToTimeString(minutesToNextStep));
|
||||||
prevPrintedLitres = printedLitres;
|
prevPrintedLitres = printedLitres;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -54,6 +58,16 @@ public class DrinkingBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static long getMinutesToNextStep(double currentLitres, long totalMinutes) {
|
||||||
|
// berechne Liter benötigt bis zum nächsten 0.25er Schritt
|
||||||
|
double litresToNextStep = 0.25 - (currentLitres % 0.25);
|
||||||
|
// berechne Minuten benötigt für 1 Liter
|
||||||
|
double minutesPerLitre = totalMinutes / 2.0;
|
||||||
|
// berechne Minuten benötigt bis zum nächsten 0.25er Schritt
|
||||||
|
return (long) (minutesPerLitre * litresToNextStep) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static String minutesToTimeString(long minutes) { // DEBUG
|
private static String minutesToTimeString(long minutes) { // DEBUG
|
||||||
var minutesBD = BigDecimal.valueOf(minutes);
|
var minutesBD = BigDecimal.valueOf(minutes);
|
||||||
BigDecimal[] hoursAndMinutes = minutesBD.divideAndRemainder(MINS_PER_HOUR_BD, MC_INTEGER);
|
BigDecimal[] hoursAndMinutes = minutesBD.divideAndRemainder(MINS_PER_HOUR_BD, MC_INTEGER);
|
||||||
|
Reference in New Issue
Block a user