style guide
This commit is contained in:
parent
6a87bb9fd3
commit
5447569e18
@ -6,28 +6,28 @@ import java.util.Random;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Vorlesung 12 - Ein- und Ausgabe - Aufgabe 1
|
* Vorlesung 12 - Ein- und Ausgabe - Aufgabe 1
|
||||||
|
*
|
||||||
* @author Sebastian Brosch
|
* @author Sebastian Brosch
|
||||||
* @see https://gitea.hb.dhbw-stuttgart.de/sebastianbrosch/VL-Programmieren/src/branch/main/VL12/Aufgabe01
|
|
||||||
*/
|
*/
|
||||||
public class Aufgabe01 {
|
public class Aufgabe01 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
final String COLUMN_SEPARATOR = "#";
|
final String COLUMN_SEPARATOR = "#";
|
||||||
final int START_KUNDENNUMMER = 100000;
|
final int START_KUNDENNUMMER = 100000;
|
||||||
int cntDataSets = 0;
|
int numberOfDatasets = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
System.out.print("Anzahl der Datensätze: ");
|
System.out.print("Anzahl der Datensätze: ");
|
||||||
cntDataSets = Integer.parseInt(System.console().readLine());
|
numberOfDatasets = Integer.parseInt(System.console().readLine());
|
||||||
|
|
||||||
// only positive numbers are valid.
|
// only positive numbers are valid.
|
||||||
if(cntDataSets <= 0) {
|
if (numberOfDatasets <= 0) {
|
||||||
System.out.println("Bitte geben Sie eine gültige Anzahl ein (min. 1)!");
|
System.out.println("Bitte geben Sie eine gültige Anzahl ein (min. 1)!");
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
System.out.println("Es wurde keine gültige Anzahl Datensätze eingegeben!");
|
System.out.println("Es wurde keine gültige Anzahl Datensätze eingegeben!");
|
||||||
}
|
}
|
||||||
} while(cntDataSets <= 0);
|
} while (numberOfDatasets <= 0);
|
||||||
|
|
||||||
StringFeld namen = new StringFeld(getPathFromPackage() + "/input/Nachnamen.TXT");
|
StringFeld namen = new StringFeld(getPathFromPackage() + "/input/Nachnamen.TXT");
|
||||||
StringFeld strassen = new StringFeld(getPathFromPackage() + "/input/Strassen.TXT");
|
StringFeld strassen = new StringFeld(getPathFromPackage() + "/input/Strassen.TXT");
|
||||||
@ -49,7 +49,7 @@ public class Aufgabe01 {
|
|||||||
FileWriter outputFixedWidth = new FileWriter(fileOutputFixedWidth);
|
FileWriter outputFixedWidth = new FileWriter(fileOutputFixedWidth);
|
||||||
FileWriter outputSeparator = new FileWriter(fileOutputSeparator);
|
FileWriter outputSeparator = new FileWriter(fileOutputSeparator);
|
||||||
|
|
||||||
for(int i = 0; i < cntDataSets; i++) {
|
for (int i = 0; i < numberOfDatasets; i++) {
|
||||||
int kundennummer = START_KUNDENNUMMER + i;
|
int kundennummer = START_KUNDENNUMMER + i;
|
||||||
int hausnummer = getRandomNumber(1, 99999);
|
int hausnummer = getRandomNumber(1, 99999);
|
||||||
int umsatz = getRandomNumber(500, 2000);
|
int umsatz = getRandomNumber(500, 2000);
|
||||||
@ -77,13 +77,16 @@ public class Aufgabe01 {
|
|||||||
|
|
||||||
outputFixedWidth.close();
|
outputFixedWidth.close();
|
||||||
outputSeparator.close();
|
outputSeparator.close();
|
||||||
} catch(Throwable e) {;}
|
} catch (Throwable e) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("Die Testdaten (" + cntDataSets + " Zeilen) wurden erzeugt.");
|
System.out.println("Die Testdaten (" + numberOfDatasets + " Zeilen) wurden erzeugt.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to determine a random number from a certain range.
|
* Method to determine a random number from a certain range.
|
||||||
|
*
|
||||||
* @param start The first number of the range.
|
* @param start The first number of the range.
|
||||||
* @param end The last number of the range.
|
* @param end The last number of the range.
|
||||||
* @return A random number from a certain range.
|
* @return A random number from a certain range.
|
||||||
@ -94,6 +97,7 @@ public class Aufgabe01 {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get the relative path based on the package name.
|
* Method to get the relative path based on the package name.
|
||||||
|
*
|
||||||
* @return The relative path of the package based on the package name.
|
* @return The relative path of the package based on the package name.
|
||||||
*/
|
*/
|
||||||
private static String getPathFromPackage() {
|
private static String getPathFromPackage() {
|
||||||
|
@ -8,6 +8,7 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A field to store some information.
|
* A field to store some information.
|
||||||
|
*
|
||||||
* @author Sebastian Brosch
|
* @author Sebastian Brosch
|
||||||
*/
|
*/
|
||||||
class StringFeld {
|
class StringFeld {
|
||||||
@ -30,6 +31,7 @@ class StringFeld {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get a value.
|
* Method to get a value.
|
||||||
|
*
|
||||||
* @param index The index of the value.
|
* @param index The index of the value.
|
||||||
* @return The value of the given index.
|
* @return The value of the given index.
|
||||||
*/
|
*/
|
||||||
@ -40,6 +42,7 @@ class StringFeld {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get a value.
|
* Method to get a value.
|
||||||
|
*
|
||||||
* @param index The index of the value.
|
* @param index The index of the value.
|
||||||
* @param maxLength The max length of the value.
|
* @param maxLength The max length of the value.
|
||||||
* @return The value of the given index.
|
* @return The value of the given index.
|
||||||
@ -56,6 +59,7 @@ class StringFeld {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get all the lines of a file.
|
* Method to get all the lines of a file.
|
||||||
|
*
|
||||||
* @param filePath The path to the file to get the lines from.
|
* @param filePath The path to the file to get the lines from.
|
||||||
* @return A list with all lines of the file.
|
* @return A list with all lines of the file.
|
||||||
*/
|
*/
|
||||||
|
@ -8,14 +8,14 @@ import java.nio.file.Paths;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Vorlesung 12 - Ein- und Ausgabe - Aufgabe 2
|
* Vorlesung 12 - Ein- und Ausgabe - Aufgabe 2
|
||||||
|
*
|
||||||
* @author Sebastian Brosch
|
* @author Sebastian Brosch
|
||||||
* @see https://gitea.hb.dhbw-stuttgart.de/sebastianbrosch/VL-Programmieren/src/branch/main/VL12/Aufgabe02
|
|
||||||
*/
|
*/
|
||||||
public class Aufgabe02 {
|
public class Aufgabe02 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
int words = 0;
|
int numberOfWords = 0;
|
||||||
int numbers = 0;
|
int numberOfNumbers = 0;
|
||||||
|
|
||||||
StringReader stringReader = new StringReader(getInputString(getPathFromPackage() + "/input/input.txt"));
|
StringReader stringReader = new StringReader(getInputString(getPathFromPackage() + "/input/input.txt"));
|
||||||
StreamTokenizer streamTokenizer = new StreamTokenizer(stringReader);
|
StreamTokenizer streamTokenizer = new StreamTokenizer(stringReader);
|
||||||
@ -23,26 +23,30 @@ public class Aufgabe02 {
|
|||||||
while (streamTokenizer.nextToken() != StreamTokenizer.TT_EOF) {
|
while (streamTokenizer.nextToken() != StreamTokenizer.TT_EOF) {
|
||||||
switch (streamTokenizer.ttype) {
|
switch (streamTokenizer.ttype) {
|
||||||
case StreamTokenizer.TT_WORD:
|
case StreamTokenizer.TT_WORD:
|
||||||
words++;
|
numberOfWords++;
|
||||||
System.out.printf("ZEICHENKETTE:\t%s\n", streamTokenizer.sval);
|
System.out.printf("ZEICHENKETTE:\t%s\n", streamTokenizer.sval);
|
||||||
break;
|
break;
|
||||||
case StreamTokenizer.TT_NUMBER:
|
case StreamTokenizer.TT_NUMBER:
|
||||||
numbers++;
|
numberOfNumbers++;
|
||||||
System.out.printf("ZAHL:\t\t%.0f\n", streamTokenizer.nval);
|
System.out.printf("ZAHL:\t\t%.0f\n", streamTokenizer.nval);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.printf("Gelesene Zahlen: %d\n", numbers);
|
System.out.printf("Gelesene Zahlen: %d\n", numberOfNumbers);
|
||||||
System.out.printf("Gelesene Zeichenketten: %d\n", words);
|
System.out.printf("Gelesene Zeichenketten: %d\n", numberOfWords);
|
||||||
System.out.printf("Insgesamt gelesene Token: %d\n", (numbers + words));
|
System.out.printf("Insgesamt gelesene Token: %d\n", (numberOfNumbers + numberOfWords));
|
||||||
} catch (Throwable e) {;}
|
} catch (Throwable e) {
|
||||||
|
;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get the content of a file as a string.
|
* Method to get the content of a file as a string.
|
||||||
|
*
|
||||||
* @param inputPath The path of the file.
|
* @param inputPath The path of the file.
|
||||||
* @return The content of the file or an empty string if the file is not available.
|
* @return The content of the file or an empty string if the file is not
|
||||||
|
* available.
|
||||||
*/
|
*/
|
||||||
private static String getInputString(String inputPath) {
|
private static String getInputString(String inputPath) {
|
||||||
try {
|
try {
|
||||||
@ -55,6 +59,7 @@ public class Aufgabe02 {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get the relative path based on the package name.
|
* Method to get the relative path based on the package name.
|
||||||
|
*
|
||||||
* @return The relative path of the package based on the package name.
|
* @return The relative path of the package based on the package name.
|
||||||
*/
|
*/
|
||||||
private static String getPathFromPackage() {
|
private static String getPathFromPackage() {
|
||||||
|
Loading…
Reference in New Issue
Block a user