add input Reading

This commit is contained in:
Matti 2024-05-01 20:06:58 +02:00
parent 970bc0ba91
commit 4fb8a4de2a
11 changed files with 170 additions and 6 deletions

1
.idea/misc.xml generated
View File

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />

View File

@ -1,4 +1,4 @@
package part2;
package part2.aufg1;
public class Anwendung {
}

View File

@ -0,0 +1,112 @@
package part2.aufg1;
import java.io.FileReader;
import java.io.LineNumberReader;
import java.util.Arrays;
public class CustomerData {
private int customNR; //count =6 digit
private String firstName; //file 20 char
private String lastName; //file 20 char
private String street; //file 20 char
private int postCode; //file =5 char
private String city; //file 20 char
private int houseNR; //random 5 digit
private double amount; //random 500-2000
private String fileEntryCSV;
StringField allFirstNames = new StringField();
StringField allLastNames = new StringField();
StringField allStreets = new StringField();
StringField allCitiesNCodes = new StringField();
public void readFirstNames(){
try{
String line;
int i = 0;
FileReader fileIN = new FileReader("C:\\Users\\dh10mbo\\OneDrive - Durr Group\\Documents\\Uni\\S2\\Repos\\S2_Aufgaben\\src\\part2\\aufg1\\input_files\\Vornamen.txt");
LineNumberReader dataIN = new LineNumberReader(fileIN);
while ((line = dataIN.readLine()) != null) {
allFirstNames.setData(line, i++);
}
fileIN.close();
}
catch (Throwable e){
System.out.println("smth went wrong with reading the first names!");
System.out.println(e);
}
}
public void readLastNames(){
try{
String line;
int i = 0;
FileReader fileIN = new FileReader("C:\\Users\\dh10mbo\\OneDrive - Durr Group\\Documents\\Uni\\S2\\Repos\\S2_Aufgaben\\src\\part2\\aufg1\\input_files\\Nachnamen.txt");
LineNumberReader dataIN = new LineNumberReader(fileIN);
while ((line = dataIN.readLine()) != null) {
allLastNames.setData(line, i++);
}
fileIN.close();
}
catch (Throwable e){
System.out.println("smth went wrong with reading the last names!");
System.out.println(e);
}
}
public void readStreets(){
try{
String line;
int i = 0;
FileReader fileIN = new FileReader("C:\\Users\\dh10mbo\\OneDrive - Durr Group\\Documents\\Uni\\S2\\Repos\\S2_Aufgaben\\src\\part2\\aufg1\\input_files\\Strassen.txt");
LineNumberReader dataIN = new LineNumberReader(fileIN);
while ((line = dataIN.readLine()) != null) {
allStreets.setData(line, i++);
}
fileIN.close();
}
catch (Throwable e){
System.out.println("smth went wrong with reading the streets!");
System.out.println(e);
}
}
public void readCities(){
try{
String line;
int i = 0;
FileReader fileIN = new FileReader("C:\\Users\\dh10mbo\\OneDrive - Durr Group\\Documents\\Uni\\S2\\Repos\\S2_Aufgaben\\src\\part2\\aufg1\\input_files\\PLZOrt.txt");
LineNumberReader dataIN = new LineNumberReader(fileIN);
while ((line = dataIN.readLine()) != null) {
allCitiesNCodes.setData(line, i++);
}
fileIN.close();
}
catch (Throwable e){
System.out.println("smth went wrong with reading the Cities!");
System.out.println(e);
}
}
public static void main(String[] args){
CustomerData data = new CustomerData();
data.readFirstNames();
System.out.println(Arrays.toString(data.allFirstNames.getAll()));
data.readLastNames();
System.out.println(Arrays.toString(data.allLastNames.getAll()));
data.readStreets();
System.out.println(Arrays.toString(data.allStreets.getAll()));
data.readCities();
System.out.println(Arrays.toString(data.allCitiesNCodes.getAll()));
}
}

View File

@ -0,0 +1,29 @@
package part2.aufg1;
public class StringField {
private String[] data = new String[25];
public void setAll(String[] data) {
this.data = data;
}
public String[] getAll() {
return data;
}
public void setData(String data, int index) {
this.data[index] = data;
}
public String getData(int index) {
return data[index];
}
public void printAll(){
for (int i=0; i< data.length; i++){
System.out.println(getData(i));
}
}
}

View File

@ -5,7 +5,7 @@ Nelkenweg
Stuttgarter Str.
Ulmer Str.
Freiburger Str.
Münchner Str.
Mönchner Str.
Goetheweg
Beethovenallee
Schillerstr.

View File

@ -0,0 +1,22 @@
package part2.aufg2;
import java.io.*;
public class Anwendung {
public static void main(String[] args){
try{
String line;
FileReader fileIN = new FileReader("C:\\Users\\dh10mbo\\OneDrive - Durr Group\\Documents\\Uni\\S2\\Repos\\S2_Aufgaben\\src\\part2\\aufg2\\files\\input\\input.txt");
LineNumberReader dataIN = new LineNumberReader(fileIN);
while ((line = dataIN.readLine()) != null) {
System.out.println(line);
}
System.out.println("end of file");
}
catch (Throwable e){
System.out.println("smth went wrong!");
System.out.println(e);
}
}
}

View File

@ -0,0 +1,2 @@
Wenn Robert mich lesen kann ist Matti cool!
Sehr cool sogar.

View File