64 lines
1.6 KiB
Java
64 lines
1.6 KiB
Java
package Uebung3_Buchungen;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.FileReader;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
public class Reader {
|
|
|
|
public static void main(String[] args) {
|
|
int buchungsnummer;
|
|
Date Buchungsdatum;
|
|
String buchungskonto;
|
|
double buchungsbetrag;
|
|
ArrayList<ArrayList> overEqual100 = new ArrayList<>();
|
|
ArrayList<ArrayList> lessEqual100 = new ArrayList<>();
|
|
String dateiName = "buchungen.text";
|
|
try (BufferedReader reader = new BufferedReader(new FileReader(dateiName))){
|
|
String line;
|
|
while (( line = reader.readLine()) != null) {
|
|
ArrayList<String> data = splitIgnoringQuotes(line);
|
|
if (Double.parseDouble(data.get(3)) < 1000) {
|
|
lessEqual100.add(data);
|
|
}else {
|
|
overEqual100.add(data);
|
|
}
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
for (ArrayList arrayList : lessEqual100) {
|
|
System.out.println(arrayList.toString());
|
|
}
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
|
|
|