done except for writing to file
This commit is contained in:
parent
4aaf422d3b
commit
7705945e9e
@ -2,14 +2,16 @@ package part2.aufg1;
|
||||
|
||||
public class Anwendung {
|
||||
public static void main(String[] args){
|
||||
int startingNR = 745002;
|
||||
int amountOfSets = 5;
|
||||
int startingNR = 420000;
|
||||
int amountOfSets = 15;
|
||||
|
||||
for (int i=0; i<amountOfSets; i++){
|
||||
CustomerData data = new CustomerData(startingNR+i);
|
||||
data.print();
|
||||
CustomerData data = new CustomerData(startingNR++);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -178,6 +178,33 @@ public class CustomerData {
|
||||
this.fileEntryCSV = customNR + "#" + firstName + "#" + lastName + "#" + street + "#" + houseNR + "#" + city + "#" + amount;
|
||||
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){
|
||||
CustomerData data = new CustomerData(123456);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user