Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Code to create fantasy words

  1. #1
    Junior Member
    Join Date
    Jul 2020
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Code to create fantasy words

    Hello,
    First of all, 3 months ago i had nothing to do with java or any other language. During Covid-19 i had alot of time and the idea of writing a fantasy book. But first of all i needed a cool new language like "elvish" from Tolkien. So i started. But after creating the first 30 words in my mind, they started to sound similar. So i thought about an app/program that could do that for me and i decided to learn programming and watched alot of youtube videos about java (I was told it is the easiest for beginners ...). The app should work like that: Click a button, receice a word.

    It took me quiet a long time watching the videos and then writing my programm in eclipse. Unfortunately i have to say, that i am proud, but not very satisfied with my work. It does, what it has to, but most of the words i get are not suitable like "iiffjn", "uuuis" or "wiwifjn". Im sure that there are much better solutions out there. And maybe someone of you can help me to enhance the code.

    Here is what i wrote:

    (Sorry for using some german words in my code, but i did not think anyone else would read it ... )

     
    "Site1: Program.java"
     
    import java.util.Random;
    import java.util.Scanner;
     
    public class program {
     
    	public static void main(String[] args) {
     
     
    		Wort1 WortNeu = new Wort1();
    		WortNeu.erstellen();
     
    	}
    }
     
    "Site2:Wort1.java"
     
    import java.util.Random;
     
    public class Wort1 {
     
    	public void erstellen () {
     
    		Random zufall = new Random ();
    		String[]KonVok = {"ba", "ca", "da", "ea", "fa", "ga", "ha", "ia", "ja", "ka", "la", "ma", "na", "oa", "pa", "ra", "sa", "ta", "ua", "va", "wa", "ya", "ae", "be", "ce", "de", "fe", "ge", "he", "ie", "je", "ke", "le", "me", "ne", "oe", "pe", "re", "se", "te", "ue", "ve", "we", "ye", "ai", "bi", "ci", "di", "ei", "fi", "gi", "hi", "ji", "ki", "li", "mi", "ni", "oi", "pi", "ri", "si", "ti", "ui", "vi", "wi", "yi", "ao", "bo", "co", "do", "eo", "fo", "go", "ho", "io", "jo", "ko", "lo", "mo", "no", "po", "ro", "so", "to", "uo", "vo", "wo", "yo", "au", "bu", "cu", "du", "eu", "fu", "gu", "hu", "iu", "ju", "ku", "lu", "mu", "nu", "ou", "pu", "ru", "su", "tu", "vu", "wu", "yu", "ay", "by", "cy", "dy", "ey", "fy", "gy", "hy", "iy", "jy", "ky", "ly", "my", "ny", "oy", "py", "ry", "sy", "ty", "uy", "vy", "wy", "aj", "bj", "cj", "dj", "ej", "fj", "gj", "hj", "ij", "kj", "lj", "mj", "nj", "oj", "pj", "rj", "sj", "tj", "uj", "vj", "wj", "yj"};
    		String[]DoppelVok = {"aa", "ee", "ii", "oo", "uu", "ae", "ai", "ao", "au", "ea", "ee", "ei", "eo", "eu", "ia", "ie", "io", "iu", "oa", "oe", "oi", "ou", "ua", "ue", "ui", "uo"};
    		String[]DoppelKon = {"ts", "st", "ng", "sb", "bs", "ls", "ch", "rr", "ll", "nn", "ff", "tt", "dd", "pp", "ss", "bb", "th"};
    		String[]Endung = {"ron", "huir", "uien", "ed", "nor", "wej", "vor", "er", "ar", "ing", "myr", "syr", "tjm","ror", "hel", "hul", "run", "cel", "fjn", "dor", "os", "es", "as", "uis", "re", "de", "ser"};
    		String[]Vokale = {"a", "e", "i", "o", "u"};
    		String[]Konsonanten = {"b", "c", "d", "f", "g", "h", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "z"};
     
    		int Chance = zufall.nextInt(10);
    		System.out.println(Chance);
     
    	if(Chance == 0) {	
    		System.out.print(DoppelVok[new Random().nextInt(DoppelVok.length)]);
    		System.out.print(KonVok[new Random().nextInt(KonVok.length)]);
    	}	
    	if(Chance == 1) {
    		System.out.print(KonVok[new Random().nextInt(KonVok.length)]);
    		System.out.print(Endung[new Random().nextInt(Endung.length)]);
    	}
    	if(Chance == 2) {
    		System.out.print(KonVok[new Random().nextInt(KonVok.length)]);
    		System.out.print(DoppelKon[new Random().nextInt(DoppelKon.length)]);
    		System.out.print(Endung[new Random().nextInt(Endung.length)]);
    	}
    	if(Chance == 3) {
    		System.out.print(Konsonanten[new Random().nextInt(Konsonanten.length)]);
    		System.out.print(Vokale[new Random().nextInt(Vokale.length)]);
    		System.out.print(KonVok[new Random().nextInt(KonVok.length)]);
    		System.out.print(Endung[new Random().nextInt(Endung.length)]);
    	}
    	if(Chance == 4) {
    		System.out.print(Vokale[new Random().nextInt(Vokale.length)]);
    		System.out.print(Endung[new Random().nextInt(Endung.length)]);
    		System.out.print(DoppelVok[new Random().nextInt(DoppelVok.length)]);
    	}
    	if(Chance == 5) {
    		System.out.print(Konsonanten[new Random().nextInt(Konsonanten.length)]);
    		System.out.print(DoppelVok[new Random().nextInt(DoppelVok.length)]);
    	}
    	if(Chance == 6) {
    		System.out.print(DoppelVok[new Random().nextInt(DoppelVok.length)]);
    		System.out.print(Konsonanten[new Random().nextInt(Konsonanten.length)]);
    		System.out.print(Endung[new Random().nextInt(Endung.length)]);
    	}	
    	if(Chance == 7) {
    		System.out.print(DoppelVok[new Random().nextInt(DoppelVok.length)]);
    		System.out.print(Endung[new Random().nextInt(Endung.length)]);
    	}
    	if(Chance == 8) {
    		System.out.print(Konsonanten[new Random().nextInt(Konsonanten.length)]);
    		System.out.print(Vokale[new Random().nextInt(Vokale.length)]);
    		System.out.print(Endung[new Random().nextInt(Endung.length)]);
    		System.out.print(Konsonanten[new Random().nextInt(Konsonanten.length)]);
    	}
    	if(Chance == 9) {
    		System.out.print(DoppelVok[new Random().nextInt(DoppelVok.length)]);
    		System.out.print(Konsonanten[new Random().nextInt(Konsonanten.length)]);
    	}
     
    	}
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    23,186
    Thanks
    53
    Thanked 2,465 Times in 2,416 Posts

    Default Re: Code to create fantasy words

    One change I see is the list of if statements should be replaced by a switch statement.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jul 2020
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Code to create fantasy words

    Quote Originally Posted by Norm View Post
    One change I see is the list of if statements should be replaced by a switch statement.
    I dont know know what a switch statement does and how to write it ...

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    23,186
    Thanks
    53
    Thanked 2,465 Times in 2,416 Posts

    Default Re: Code to create fantasy words

    Here's a link to the tutorial: https://docs.oracle.com/javase/tutor...ts/switch.html
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Create non repeated words
    By toddy in forum Java Theory & Questions
    Replies: 3
    Last Post: June 21st, 2014, 07:25 PM
  2. Replies: 2
    Last Post: February 10th, 2014, 06:24 AM
  3. Replies: 12
    Last Post: March 17th, 2013, 01:38 AM
  4. A Program that will ask five letters and create a possible words
    By jms25 in forum Java Theory & Questions
    Replies: 11
    Last Post: September 23rd, 2012, 09:40 PM
  5. Fantasy Football Offline Draft Manager Program
    By aussiemcgr in forum Java Theory & Questions
    Replies: 0
    Last Post: September 6th, 2010, 09:52 AM