73 lines
2.2 KiB
Java
73 lines
2.2 KiB
Java
package Uebung3_Buchungen;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.FileReader;
|
|
import java.io.IOException;
|
|
import java.time.LocalDate;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
|
|
public class BuchungenAufgabe {
|
|
|
|
public static void main(String[] args) throws FileNotFoundException, IOException {
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
|
ArrayList<Buchung> under1000 = new ArrayList<>();
|
|
ArrayList<Buchung> over1000 = new ArrayList<>();
|
|
|
|
try(BufferedReader reader = new BufferedReader(new FileReader("buchungen2.text"))){
|
|
String line;
|
|
while((line = reader.readLine()) != null){
|
|
String[] parts = line.split("\"");
|
|
String[] numsParts = parts[0].split("\\s+");
|
|
int bnummer = Integer.parseInt(numsParts[0]);
|
|
LocalDate date = LocalDate.parse(numsParts[1], formatter);
|
|
String name = parts[2];
|
|
double value = Double.parseDouble(parts[2]);
|
|
|
|
if(value >= 1000.00) {
|
|
over1000.add(new Buchung(bnummer, date, name, value));
|
|
}else if(value < 1000.00) {
|
|
under1000.add(new Buchung(bnummer, date, name, value));
|
|
}
|
|
}
|
|
double gesammtSumme = 0.0;
|
|
for ( Buchung buchung : under1000) {
|
|
System.out.println(buchung.toString());
|
|
gesammtSumme += buchung.getBuchungsbetrag();
|
|
}
|
|
for ( Buchung buchung : over1000) {
|
|
System.out.println(buchung.toString());
|
|
gesammtSumme += buchung.getBuchungsbetrag();
|
|
}
|
|
System.out.println("Gesammte Summe: " + gesammtSumme);
|
|
}
|
|
}
|
|
public static ArrayList<String> splitIgnoringQuotes(String input) {
|
|
ArrayList<String> parts = new ArrayList<>();
|
|
StringBuilder sb = new StringBuilder();
|
|
boolean insideQuotes = false;
|
|
|
|
for (char c : input.toCharArray()) {
|
|
if (c == '\"') {
|
|
insideQuotes = !insideQuotes;
|
|
} else if (c == ' ' && !insideQuotes) {
|
|
parts.add(sb.toString());
|
|
sb.setLength(0);
|
|
} else {
|
|
sb.append(c);
|
|
}
|
|
}
|
|
|
|
if (sb.length() > 0) {
|
|
parts.add(sb.toString());
|
|
}
|
|
|
|
return parts;
|
|
}
|
|
}
|
|
|
|
|
|
|