Compare commits

...

3 Commits

2 changed files with 101 additions and 19 deletions

View File

@ -164,43 +164,55 @@ class Darlehenberechner {
.setAnfangsmonat(YearMonth.of(2024, Month.SEPTEMBER)) .setAnfangsmonat(YearMonth.of(2024, Month.SEPTEMBER))
).berechneWerte();*/ ).berechneWerte();*/
if (args.length == 0) {
askParametersAndRun();
} else {
parseParametersAndRun(args);
}
}
private static void askParametersAndRun() throws IOException {
DECIMAL_FORMAT.setParseBigDecimal(true); DECIMAL_FORMAT.setParseBigDecimal(true);
var konfig = new Konfiguration(); var konfig = new Konfiguration();
var dis = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)); var br = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
System.out.print("Darlehenswert: "); System.out.print("Darlehenswert: ");
konfig.setDarlehenswert((BigDecimal) DECIMAL_FORMAT.parse(dis.readLine())); konfig.setDarlehenswert((BigDecimal) DECIMAL_FORMAT.parse(br.readLine()));
System.out.print("Zinssatz: "); System.out.print("Zinssatz: ");
konfig.setZinssatzProzent((BigDecimal) DECIMAL_FORMAT.parse(dis.readLine())); konfig.setZinssatzProzent((BigDecimal) DECIMAL_FORMAT.parse(br.readLine()));
System.out.print("Monatliche Rate: "); System.out.print("Monatliche Rate: ");
konfig.setMonatlicheRate((BigDecimal) DECIMAL_FORMAT.parse(dis.readLine())); konfig.setMonatlicheRate((BigDecimal) DECIMAL_FORMAT.parse(br.readLine()));
System.out.print("Monat erste Rate(z.B. 2007-12): "); System.out.print("Monat erste Rate(z.B. 2007-12): ");
konfig.setAnfangsmonat(YearMonth.parse(dis.readLine())); konfig.setAnfangsmonat(YearMonth.parse(br.readLine()));
System.out.print("Laufzeit in Jahren(optional Jahre:Monate): "); System.out.print("Laufzeit in Jahren(optional Jahre:Monate): ");
String in = dis.readLine(); String in = br.readLine();
if (in != null && !in.isBlank()) { if (in != null && !in.isBlank()) {
String[] split = in.split(":"); String[] split = in.split(":");
konfig.setLaufzeit(Integer.parseInt(split[0]), Integer.parseInt(split[1])); konfig.setLaufzeit(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
} else { } else {
System.out.print("Restschuld(optional): "); System.out.print("Restschuld(optional): ");
in = dis.readLine(); in = br.readLine();
if (in != null && !in.isBlank()) { if (in != null && !in.isBlank()) {
konfig.setRestschuld((BigDecimal) DECIMAL_FORMAT.parse(in)); konfig.setRestschuld((BigDecimal) DECIMAL_FORMAT.parse(in));
} }
} }
System.out.print("Anzahl tilgungsfreier Monate(optional): "); System.out.print("Anzahl tilgungsfreier Monate(optional): ");
in = dis.readLine(); in = br.readLine();
if (in != null && !in.isBlank()) { if (in != null && !in.isBlank()) {
konfig.setTilgungsfreieZeit(Integer.parseInt(in)); konfig.setTilgungsfreieZeit(Integer.parseInt(in));
} }
System.out.print("Sondertilgungssatz(optional): "); System.out.print("Sondertilgungssatz(optional): ");
in = dis.readLine(); in = br.readLine();
if (in != null && !in.isBlank()) { if (in != null && !in.isBlank()) {
konfig.setSondertilgungProzent((BigDecimal) DECIMAL_FORMAT.parse(in)); konfig.setSondertilgungProzent((BigDecimal) DECIMAL_FORMAT.parse(in));
} }
new Darlehenberechner(konfig).berechneWerte(); new Darlehenberechner(konfig).berechneWerte();
}
/*var konfig = new Konfiguration();
private static void parseParametersAndRun(String[] args) {
var konfig = new Konfiguration();
int count = 0; int count = 0;
DECIMAL_FORMAT.setParseBigDecimal(true); DECIMAL_FORMAT.setParseBigDecimal(true);
while (count < args.length) { while (count < args.length) {
@ -239,7 +251,7 @@ class Darlehenberechner {
} }
count++; count++;
} }
new Darlehenberechner(konfig).berechneWerte();*/ new Darlehenberechner(konfig).berechneWerte();
} }

View File

@ -1,14 +1,18 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.MathContext; import java.math.MathContext;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -60,13 +64,79 @@ public class LoadingBar {
} }
public static void main(String[] args) { public static void main(String[] args) throws IOException {
if (args.length > 0 && Objects.equals(args[0], "--help")) { if (args.length == 0) {
askParametersAndRun();
} else {
parseParametersAndRun(args);
}
}
private static void askParametersAndRun() throws IOException {
var br = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
System.out.print("Ankunftszeit: ");
String startTimeRaw = br.readLine();
var startTime = LocalTime.parse(startTimeRaw, TIME_FORMATTER);
handleMittagspause(br, startTime);
handleZapfenstreich(br, startTime);
}
private static void handleMittagspause(BufferedReader br, LocalTime startTime) throws IOException {
System.out.print("Mittagspause verschieben um (optional): ");
String mittagspauseOffsetRaw = br.readLine();
if (mittagspauseOffsetRaw != null && !mittagspauseOffsetRaw.isBlank()) {
var mittagspauseOffset = Integer.parseInt(mittagspauseOffsetRaw);
showLoadingBarMittagspause(startTime, mittagspauseOffset);
return;
}
System.out.print("Mittagspause um (optional): ");
String manualMittagspauseRaw = br.readLine();
if (mittagspauseOffsetRaw != null && !mittagspauseOffsetRaw.isBlank()) {
var manualMittagspause = LocalTime.parse(manualMittagspauseRaw, TIME_FORMATTER);
showLoadingBarMittagspause(startTime, manualMittagspause);
} else {
showLoadingBarMittagspause(startTime);
}
}
private static void handleZapfenstreich(BufferedReader br, LocalTime startTime) throws IOException {
System.out.print("Mittagspause hat gedauert (optional): ");
String mittagspauseDurationRaw = br.readLine();
Integer mittagspauseDuration = null;
if (mittagspauseDurationRaw != null && !mittagspauseDurationRaw.isBlank()) {
mittagspauseDuration = Integer.valueOf(mittagspauseDurationRaw);
}
System.out.print("Feierabend verschieben um (optional): ");
String zapfenstreichOffsetRaw = br.readLine();
Integer zapfenstreichOffset = null;
if (zapfenstreichOffsetRaw != null && !zapfenstreichOffsetRaw.isBlank()) {
zapfenstreichOffset = Integer.valueOf(zapfenstreichOffsetRaw);
showLoadingBarZapfenstreich(startTime, mittagspauseDuration, zapfenstreichOffset);
return;
}
System.out.print("Manuelle Uhrzeit Feierabend (optional): ");
String manualZapfenstreichRaw = br.readLine();
LocalTime manualZapfenstreich = null;
if (manualZapfenstreichRaw != null && !manualZapfenstreichRaw.isBlank()) {
manualZapfenstreich = LocalTime.parse(manualZapfenstreichRaw, TIME_FORMATTER);
showLoadingBarZapfenstreich(startTime, mittagspauseDuration, manualZapfenstreich);
return;
}
showLoadingBarZapfenstreich(startTime, mittagspauseDuration);
}
private static void parseParametersAndRun(String[] args) {
String nextArg = args[0];
if ("--help".equals(nextArg)) {
printHelp(); printHelp();
return; return;
} }
verifyMinimumNumberOfArgs(args); verifyMinimumNumberOfArgs(args);
String nextArg = args[0];
verifyTimeFormat(nextArg, "Erstes Argument"); verifyTimeFormat(nextArg, "Erstes Argument");
var startTime = LocalTime.parse(nextArg, TIME_FORMATTER); var startTime = LocalTime.parse(nextArg, TIME_FORMATTER);
nextArg = args[1]; nextArg = args[1];
@ -91,13 +161,12 @@ public class LoadingBar {
return; return;
} }
verifyTimeFormat(nextArg, "Argument nach " + DaySection.MITTAG.getParam()); verifyTimeFormat(nextArg, "Argument nach " + DaySection.MITTAG.getParam());
var maxMittagspause = LocalTime.parse(nextArg, TIME_FORMATTER); var manualMittagspause = LocalTime.parse(nextArg, TIME_FORMATTER);
showLoadingBarMittagspause(startTime, maxMittagspause); showLoadingBarMittagspause(startTime, manualMittagspause);
} }
private static void handleZapfenstreich(String[] args, LocalTime startTime) { private static void handleZapfenstreich(String[] args, LocalTime startTime) {
Integer lunchDuration = null;
if (args.length == 2) { if (args.length == 2) {
showLoadingBarZapfenstreich(startTime); showLoadingBarZapfenstreich(startTime);
return; return;
@ -105,6 +174,7 @@ public class LoadingBar {
String nextArg = args[2]; String nextArg = args[2];
LocalTime maxZapfenstreich = null; LocalTime maxZapfenstreich = null;
int endTimeOffset = 0; int endTimeOffset = 0;
Integer lunchDuration = null;
if (TIME_PATTERN.matcher(nextArg).matches()) { if (TIME_PATTERN.matcher(nextArg).matches()) {
maxZapfenstreich = LocalTime.parse(nextArg, TIME_FORMATTER); maxZapfenstreich = LocalTime.parse(nextArg, TIME_FORMATTER);
} else if (OFFSET_PATTERN.matcher(nextArg).matches()) { } else if (OFFSET_PATTERN.matcher(nextArg).matches()) {