done except for writing to file

This commit is contained in:
Matti 2024-05-01 22:48:29 +02:00
parent 4aaf422d3b
commit 7705945e9e
2 changed files with 34 additions and 5 deletions

View File

@ -2,14 +2,16 @@ package part2.aufg1;
public class Anwendung { public class Anwendung {
public static void main(String[] args){ public static void main(String[] args){
int startingNR = 745002; int startingNR = 420000;
int amountOfSets = 5; int amountOfSets = 15;
for (int i=0; i<amountOfSets; i++){ for (int i=0; i<amountOfSets; i++){
CustomerData data = new CustomerData(startingNR+i); CustomerData data = new CustomerData(startingNR++);
data.print(); System.out.println(data.getSpacedValues());
}
for (int i=0; i<amountOfSets; i++){
CustomerData data = new CustomerData(startingNR++);
System.out.println(data.getCSV()); System.out.println(data.getCSV());
System.out.println();
} }
} }
} }

View File

@ -178,6 +178,33 @@ public class CustomerData {
this.fileEntryCSV = customNR + "#" + firstName + "#" + lastName + "#" + street + "#" + houseNR + "#" + city + "#" + amount; this.fileEntryCSV = customNR + "#" + firstName + "#" + lastName + "#" + street + "#" + houseNR + "#" + city + "#" + amount;
return this.fileEntryCSV; return this.fileEntryCSV;
} }
private String addWhitespaceUntilLenght(String string, int length, char filler){
if (string.length()>length){
throw new RuntimeException("\nInput String \n" + string +"\nis longer than the allowed length of " + length);
}else {
while (string.length()<length){
string += filler;
}
}
return string;
}
public String getSpacedValues(){
int customNR = this.customNR;
String firstnameLocal = this.firstName;
String lastnameLocal = this.lastName;
String streetLocal = this.street;
int houseNR = this.houseNR;
String cityNCode = this.city;
String customNRString = addWhitespaceUntilLenght(customNR + "", 6, ' ');
firstnameLocal = addWhitespaceUntilLenght(firstnameLocal, 20, ' ');
lastnameLocal = addWhitespaceUntilLenght(lastnameLocal, 20, ' ');
streetLocal = addWhitespaceUntilLenght(streetLocal, 20, ' ');
String houseNRString = addWhitespaceUntilLenght(houseNR+"", 5, ' ');
cityNCode = addWhitespaceUntilLenght(cityNCode, 26, ' '); // 26 because postCode is in there too
return customNRString + " " + firstnameLocal + " " + lastnameLocal + " " + streetLocal + " " + houseNRString + " " + cityNCode + " " + amount;
}
public static void main(String[] args){ public static void main(String[] args){
CustomerData data = new CustomerData(123456); CustomerData data = new CustomerData(123456);