From 438fdeef0c7731d8693d0e898b4261beab8cdf58 Mon Sep 17 00:00:00 2001 From: Matti Date: Fri, 10 May 2024 20:30:02 +0200 Subject: [PATCH] Cleanup VL 3 --- src/Main.java | 17 ++++++++--------- src/part3/aufg1/Anwendung.java | 3 ++- src/part3/aufg1/GenericStack.java | 6 +++--- src/part3/aufg1/IntStack.java | 3 ++- src/part3/aufg2/Schlenglein.java | 9 ++++++++- src/part3/aufg3/Anwendung.java | 2 +- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/Main.java b/src/Main.java index 47f9e0b..c4c987d 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,17 +1,16 @@ // Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`, // then press Enter. You can now see whitespace characters in your code. + +import part3.aufg3.Anwendung; public class Main { public static void main(String[] args) { - // Press Alt+Eingabe with your caret at the highlighted text to see how - // IntelliJ IDEA suggests fixing it. - System.out.println("Hello and welcome!"); + int size; + int MAX_LENGTH = 3; + int MIN_LENGTH = 10; - // Press Umschalt+F10 or click the green arrow button in the gutter to run the code. - for (int i = 1; i <= 5; i++) { - - // Press Umschalt+F9 to start debugging your code. We have set one breakpoint - // for you, but you can always add more by pressing Strg+F8. - System.out.println("i = " + i); + for (int i = 0; i <25; i++) { + size = (int) (Math.random() * MAX_LENGTH); + System.out.println(size); } } } \ No newline at end of file diff --git a/src/part3/aufg1/Anwendung.java b/src/part3/aufg1/Anwendung.java index 9ac112b..d35accd 100644 --- a/src/part3/aufg1/Anwendung.java +++ b/src/part3/aufg1/Anwendung.java @@ -45,10 +45,11 @@ public class Anwendung { myStack.print(); myStack.p_push(1); - myStack.p_push('B'); + myStack.p_push('J'); myStack.p_push(true); myStack.p_pop(); + myStack.p_push("\"Ich Liebe Generische Typen\""); } diff --git a/src/part3/aufg1/GenericStack.java b/src/part3/aufg1/GenericStack.java index b44353a..55a9e96 100644 --- a/src/part3/aufg1/GenericStack.java +++ b/src/part3/aufg1/GenericStack.java @@ -34,10 +34,11 @@ public class GenericStack { } public Object[] toArray(){ + Object[] retArray = new Object[this.firstFreeIndex]; + if (this.firstFreeIndex<1){ return new Object[0]; } - Object[] retArray = new Object[this.firstFreeIndex]; for (int i=0; i { public void print(){ System.out.println(Arrays.toString(this.toArray())); } -} - +} \ No newline at end of file diff --git a/src/part3/aufg1/IntStack.java b/src/part3/aufg1/IntStack.java index 8f59b05..5319e75 100644 --- a/src/part3/aufg1/IntStack.java +++ b/src/part3/aufg1/IntStack.java @@ -34,10 +34,11 @@ public class IntStack { } public int[] toArray(){ + int[] retArray = new int[firstFreeIndex]; + if (firstFreeIndex<1){ return new int[0]; } - int[] retArray = new int[firstFreeIndex]; for (int i=0; i{ this.maxSize = 100; myArray = new Object[this.maxSize]; } + public void add(T t){ this.myArray[this.numberOfElements] = t; this.numberOfElements++; @@ -19,18 +20,24 @@ public class Schlenglein { public T get(){ T retValue = (T) this.myArray[0]; + for (int i=0; i