diff --git a/bin/Grundlagen.class b/bin/Grundlagen.class index 3e6d719..617f33b 100644 Binary files a/bin/Grundlagen.class and b/bin/Grundlagen.class differ diff --git a/bin/Testcode.class b/bin/Testcode.class index fb5fa15..3b8a146 100644 Binary files a/bin/Testcode.class and b/bin/Testcode.class differ diff --git a/src/Grundlagen.java b/src/Grundlagen.java index 0eb3e88..d6e5cbc 100644 --- a/src/Grundlagen.java +++ b/src/Grundlagen.java @@ -1,3 +1,5 @@ +import java.util.Random; + import javax.swing.JOptionPane; public class Grundlagen { @@ -20,16 +22,16 @@ public class Grundlagen { if (x > 101) { System.out.println("Der Wert ist grösser als 101"); } else { - System.out.println("Der Wert ist kleiner als 101"); + System.out.println("Der Wert ist kleiner als 101"); } // Iteration int anzahlDurchgaenge = 1; - while(anzahlDurchgaenge <= 5) { + while (anzahlDurchgaenge <= 5) { System.out.println("Durchgang nr. " + anzahlDurchgaenge); anzahlDurchgaenge = anzahlDurchgaenge + 1; } - + // Lückentexte / kombination aus variablen, print und if/else // Popups mit User Input @@ -43,7 +45,7 @@ public class Grundlagen { String h = JOptionPane.showInputDialog("Please enter an object"); // Error message - + if (a == null || a.trim().isEmpty()) { System.out.println("Missing word(s) or canceled."); } else if (b == null || b.trim().isEmpty()) { @@ -68,5 +70,30 @@ public class Grundlagen { System.out.println(c + " as (the) " + d + " They're hair as " + e + " as (the) " + f + "."); System.out.println("It was a " + g + " day, after a long journey they finally found their " + h); } + + // Print text + + 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,"); + System.out.println("I'll lend you a helping hand."); + + // Creating a Random object + Random random = new Random(); + + // Define the range for xx, yy and zz + int minRange = -10000; + int maxRange = 10000; + + // Generate random values for xx, zz and yy within the specified range + int xx = random.nextInt(maxRange - minRange + 1) + minRange; + int yy = random.nextInt(maxRange - minRange + 1) + minRange; + int zz = random.nextInt(maxRange - minRange + 1) + minRange; + + int sum = xx + yy + zz; + + System.out.println("The sum of " + xx + ", " + yy + " and " + zz + " is: " + sum); + + System.out.println("May the code be with you!"); } } \ No newline at end of file diff --git a/src/Testcode.java b/src/Testcode.java index 59c83b5..6ae107d 100644 --- a/src/Testcode.java +++ b/src/Testcode.java @@ -1,67 +1,6 @@ -import java.util.Random; - -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,"); - System.out.println("I'll lend you a helping hand."); - - // Creating a Random object - Random random = new Random(); - // Define the range for x, y and z - int minRange = -10000; - int maxRange = 10000; - - // Generate random values for x and y within the specified range - int x = random.nextInt(maxRange - minRange + 1) + minRange; - int y = random.nextInt(maxRange - minRange + 1) + minRange; - int z = random.nextInt(maxRange - minRange + 1) + minRange; - - int sum = x + y + z; - - 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 - 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"); - - 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 { - 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); - } + } }