diff --git a/bin/Grundlagen.class b/bin/Grundlagen.class new file mode 100644 index 0000000..123b7aa Binary files /dev/null and b/bin/Grundlagen.class differ diff --git a/bin/Testcode.class b/bin/Testcode.class index c555213..fb5fa15 100644 Binary files a/bin/Testcode.class and b/bin/Testcode.class differ diff --git a/src/Grundlagen.java b/src/Grundlagen.java index df1ef38..c4170c7 100644 --- a/src/Grundlagen.java +++ b/src/Grundlagen.java @@ -1,3 +1,5 @@ +import javax.swing.JOptionPane; + public class Grundlagen { public static void main(String[] args) { // Hello World @@ -27,5 +29,47 @@ public class Grundlagen { System.out.println("Durchgang nr. " + anzahlDurchgaenge); anzahlDurchgaenge = anzahlDurchgaenge + 1; } + + // Lückentexte / kombination aus variablen, print und if/else + // Display a popup dialog and get user input + + // Popups mit User Input + String a = JOptionPane.showInputDialog("Please enter a verb (-ing):"); + String b = JOptionPane.showInputDialog("Please enter a location:"); + String c = JOptionPane.showInputDialog("Please enter a color:"); + String d = JOptionPane.showInputDialog("Please enter an object in that color:"); + String e = JOptionPane.showInputDialog("Please enter a diffrent color:"); + String f = JOptionPane.showInputDialog("Please enter an object in that color:"); + String g = JOptionPane.showInputDialog("Please enter an adjective:"); + String h = JOptionPane.showInputDialog("Please enter an object"); + + // Error message + + if ((a == null || a.trim().isEmpty()) && (b == null || b.trim().isEmpty())) { + System.out.println("Missing word(s) or canceled."); + } else if (a == null || a.trim().isEmpty()) { + System.out.println("Missing word(s) or canceled."); + } else if (b == null || b.trim().isEmpty()) { + System.out.println("Missing word(s) or canceled."); + } else if (c == null || c.trim().isEmpty()) { + System.out.println("Missing word(s) or canceled."); + } else if (d == null || d.trim().isEmpty()) { + System.out.println("Missing word(s) or canceled."); + } else if (e == null || e.trim().isEmpty()) { + System.out.println("Missing word(s) or canceled."); + } else if (f == null || f.trim().isEmpty()) { + System.out.println("Missing word(s) or canceled."); + } else if (g == null || g.trim().isEmpty()) { + System.out.println("Missing word(s) or canceled."); + } else if (h == null || h.trim().isEmpty()) { + System.out.println("Missing word(s) or canceled."); + } else { + + // Lückentext mit variablen + + System.out.println("They where " + a + " throw a " + b + ". They're eyes where "); + System.out.println(c + " as the " + d + " They're hair as " + e + " as " + f + "."); + System.out.println("It was a " + g + " day, after a long journey they finally found their " + h); + } } } \ No newline at end of file diff --git a/src/Testcode.java b/src/Testcode.java index 1029ed1..59c83b5 100644 --- a/src/Testcode.java +++ b/src/Testcode.java @@ -4,6 +4,7 @@ import javax.swing.JOptionPane; public class Testcode { public static void main(String[] args) { + System.out.println("A code request you have made,"); System.out.println("Fear not, for I am here to aid."); System.out.println("In Java, a language so grand,"); @@ -23,13 +24,13 @@ public class Testcode { int sum = x + y + z; - System.out.println("The sum of " + x + " " + y + " and " + z + " is: " + sum); + System.out.println("The sum of " + x + ", " + y + " and " + z + " is: " + sum); System.out.println("May the code be with you!"); // Testing Inputs with a gap text - // Display a popup dialog and get user input + // Display a popup dialog and get user input String a = JOptionPane.showInputDialog("Please enter a verb (-ing):"); String b = JOptionPane.showInputDialog("Please enter a location:"); String c = JOptionPane.showInputDialog("Please enter a color:");