Archive for the ‘Java’ Category.

Adressen generieren mit Java

Vor einiger Zeit habe ich einen einfachen Generator für Adressen geschrieben, mit dem man unter anderem Test-Datenbanken befüllen kann. Anbei der Java-Quellcode, der sich auch leicht für andere Sprachen adaptieren lässt.

/**
 *
 * @author Uwe Ziegenhagen, www.uweziegenhagen.de
 * Releaseversion vom 13.12.2008
 */
 
import java.util.*;
 
public class Addressmaker {
 
    // Zahlenformat, um PLZ der Form 0xxxx darzustellen
    static java.text.DecimalFormat format =  new java.text.DecimalFormat("00000");
    // Vornamen-Array
    static String[] vornamen = new String[]{"Uwe","Andreas","Max","Moritz","Susi",
    "Steffi","Janine","Tim","Tom","Marko","Hans","Thomas","Maria","Bernd","Mandy",
    "Ben","Thorsten","Sabine","Ines","Isabell","Maria","Nicole","Sabrina","Jenny",
    "Klaus","Heinz","Sabrina", "Tatjana","Felix","Patricia-Elisabeth","Maria Theresia"};
    // Nachnamen-Array
    static String[] nachnamen = new String[]{"Meier","Meyer","Mayer","Müller","Schulze","Lehmann",
    "Köster","Schmidt","Schuster","Wagner","Schmied","Küster","Möller","Berger","Grünwald","Meier-Lehmann",
    "Schulze-Müller","von Fallersleben-Burghausen"};
 
    // ein paar Initiale, könnte man auch aus den Namen entnehmen
    static String[] initial = new String[]{" "," "," "," "," A. "," B. "," C. "," D. "," E. "," "," "};
    // Für Adressen der Form 10a oder b
    static String[] adressinitial = new String[]{"","a","b","c","d","","","","","",""};
    // Adresszusätze
    static String[] adresszusatz = new String[]{"bei Schmidt","c/o Schmidt","p.Adr. Max Mustermann"};
    // Ortsnamen sind zusammengesetzt aus Präfix und Suffix
    static String[] ortsprefix = new String[]{"Wald","Wiesen","Groß","Klein","Mittel","Ober","Ham","Nieder","Alt","Alten",
    "Königs","Langen","Moos","Mühl","Morgen","Schön","Tannen","Vogel","Wolfen","Kirch","Bären","Heide","Hohen","Breiten","Ehren","Eber",
    "Fichten","Grün","Roten", "Ehr"};
    static String[] ortssuffix = new String[]{"heim","dorf","hausen","burg","ow","au","furt","stein","aue","finow","tal","thal"};
 
    // Straßen setzen sich ebenso zusammen aus Suffix und Präfix
    static String[] strassenprefix = new String[]{"Wald","Wiesen","Amsel","Drossel","Finken","Wasser","Sonnen","Schiller","Goethe","Nachtigall","Spatzen"};
    static String[] strassensuffix = new String[]{"straße","weg","gasse","allee","platz"};
 
    // Domains für die Email-Adresse
    static String[] domains = new String[]{".info",".de",".com",".info",".ac.uk",".ru",".ac.jp"};
 
    // um später ein paar Ersetzungen zu machen
    static String vname = "";
    static String nname = "";
 
 
    public static void main(String[] args) {
        // initialisiere den Zufallszahlengenerator
        Random generator = new Random(new Date().getTime());
        // wieviele Adressen sollen generiert werden
        int wieoft = 10;
        // Email-Adressen erstellen ja oder nein
        boolean email = true;
 
        for (int i=0;i<wieoft;i++){
            // Generiere Vor- und Nachnamen
            vname = vornamen[generator.nextInt(vornamen.length)];
            nname = nachnamen[generator.nextInt(nachnamen.length)];
 
            // Gib Vor- und Nachnamen mit eventuellem Initial aus
            System.out.print(vname + initial[generator.nextInt(initial.length)] +
                nname + "\n");
 
            // wenn nächste Random-Zahl < 3 dann generiere Adresszusatz
            if (generator.nextInt(100)<3){
                System.out.println(adresszusatz[generator.nextInt(adresszusatz.length)]);
            }
 
            // Generiere Strassennamen
            System.out.print(strassenprefix[generator.nextInt(strassenprefix.length)] +
                strassensuffix[generator.nextInt(strassensuffix.length)]+ " " + generator.nextInt(99) + adressinitial[generator.nextInt(adressinitial.length)] +  "\n");
 
            // Generiere PLZ und Ortsnamen
            System.out.print(format.format(generator.nextInt(99999)) + " " +
                ortsprefix[generator.nextInt(ortsprefix.length)] +
                ortssuffix[generator.nextInt(ortssuffix.length)]+"\n");
 
            // Wenn Email-Adressen generiert werden sollen, dann
            // ersetze Umlaute und generiere die Adresse
            if (email==true){
                vname = vname.replaceAll("ö", "oe");
                vname = vname.replaceAll("ä", "ae");
                vname = vname.replaceAll("ü", "ue");
                nname = nname.replaceAll("ö", "oe");
                nname = nname.replaceAll("ä", "ae");
                nname = nname.replaceAll("ü", "ue");
                nname = nname.replaceAll(" ", ".");
                System.out.println(vname.toLowerCase() + "." + nname.toLowerCase() + "@" +
                        ortssuffix[generator.nextInt(ortssuffix.length)] +
                        domains[generator.nextInt(domains.length)]);
        }
        // abschließendes \n
        System.out.print("\n");
        }
    }
}

Uwe

Uwe Ziegenhagen has been working with LaTeX for more than a decade. Besides TeX/LaTeX he likes to work with Python, Rasberry/Arduino and his digital camera.

More Posts - Website

Pseudo-Adressen generieren

Vor einiger Zeit habe ich mal ein paar Zeilen Java zusammengeschustert, um Pseudo-Adressen zu generieren. Hier der Quellcode, der weder sonderlich kompakt noch schön ist, seinen Zweck aber erfüllt:

/**
 *
 * @author Uwe Ziegenhagen, www.uweziegenhagen.de
 */
 
import java.util.*;
 
public class Addressmaker {
    static java.text.DecimalFormat format =  new java.text.DecimalFormat("00000");
    static String[] vornamen = new String[]{"Uwe","Andreas","Max","Moritz","Susi","Steffi","Janine","Tim","Tom","Marko","Hans","Thomas","Maria",
    "Bernd","Mandy","Ben","Thorsten","Sabine","Isabell","Doreen", "Nicole","Sabrina","Jenny","Klaus","Heinz","Sabrina"};
 
    static String[] nachnamen = new String[]{"Meier","Meyer","Mayer","Müller","Schulze","Lehmann",
    "Köster","Schmidt","Schuster","Wagner","Schmied","Küster","Möller"};
 
    static String[] initial = new String[]{" "," "," "," A. "," B. "," C. "," D. "," E. "," "," "};
    static String[] adressinitial = new String[]{"","a","b","c","d","","","","","",""};
    static String[] adresszusatz = new String[]{"bei Schmidt","c/o Schmidt","p.Adr. Max Mustermann"};
 
    static String[] ortsprefix = new String[]{"Wald","Wiesen","Groß","Klein","Mittel","Ober","Ham","Nieder","Alt","Alten",
    "Königs","Langen","Moos","Mühl","Morgen","Schön","Tannen","Vogel","Wolfen","Kirch","Bären","Heide","Hohen","Breiten","Ehren","Eber","Fichten","Grün"};
 
    static String[] ortssuffix = new String[]{"heim","dorf","hausen","burg","ow","au","furt","stein","aue","finow","tal","thal"};
    static String[] strassenprefix = new String[]{"Wald","Wiesen","Amsel","Drossel","Finken","Wasser","Sonnen","Schiller","Goethe","Nachtigall","Spatzen"};
    static String[] strassensuffix = new String[]{"straße","weg","gasse","allee","platz"};
    static String[] domains = new String[]{".info",".de",".com",".info",".ac.uk",".ru",".ac.jp"};
 
    static String vname = "";
    static String nname = ""; 
 
    public static void main(String[] args) {
        Random generator = new Random(new Date().getTime());
 
        int wieoft = 100;
        boolean email = true;
 
        for (int i=0;i<wieoft;i++){
            vname = vornamen[generator.nextInt(vornamen.length)];
            nname = nachnamen[generator.nextInt(nachnamen.length)];
 
        System.out.print(vname + initial[generator.nextInt(initial.length)] +  
                 nname + "\n");
 
        if (generator.nextInt(100)<3){
                    System.out.println(adresszusatz[generator.nextInt(adresszusatz.length)]);   
 
        }        
 
        System.out.print(strassenprefix[generator.nextInt(strassenprefix.length)] + 
                strassensuffix[generator.nextInt(strassensuffix.length)]+ " " + generator.nextInt(99) + adressinitial[generator.nextInt(adressinitial.length)] +  "\n");
 
        System.out.print(format.format(generator.nextInt(99999)) + " " + 
                ortsprefix[generator.nextInt(ortsprefix.length)] + 
                ortssuffix[generator.nextInt(ortssuffix.length)]+"\n");
 
        if (email==true){
            vname = vname.replaceAll("ö", "oe");
            vname = vname.replaceAll("ä", "ae");
            vname = vname.replaceAll("ü", "ue");
            nname = nname.replaceAll("ö", "oe");
            nname = nname.replaceAll("ä", "ae");
            nname = nname.replaceAll("ü", "ue");
            System.out.println(vname.toLowerCase() + "." + nname.toLowerCase() + "@" + ortssuffix[generator.nextInt(ortssuffix.length)] + domains[generator.nextInt(domains.length)]);
        }
 
        System.out.print("\n");
        }
 
    }
 
}

Uwe

Uwe Ziegenhagen has been working with LaTeX for more than a decade. Besides TeX/LaTeX he likes to work with Python, Rasberry/Arduino and his digital camera.

More Posts - Website