Compare commits
No commits in common. "master" and "Nitro" have entirely different histories.
|
@ -6,7 +6,6 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="beispieleVL"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
|
|
|
@ -1,110 +1,8 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
|
||||
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
|
||||
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
|
||||
org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
|
||||
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
|
||||
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
|
||||
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
|
||||
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
|
||||
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
|
||||
org.eclipse.jdt.core.compiler.compliance=17
|
||||
org.eclipse.jdt.core.compiler.problem.APILeak=warning
|
||||
org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
|
||||
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
|
||||
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
|
||||
org.eclipse.jdt.core.compiler.problem.deadCode=warning
|
||||
org.eclipse.jdt.core.compiler.problem.deprecation=warning
|
||||
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
|
||||
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
|
||||
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
|
||||
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
|
||||
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
|
||||
org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
|
||||
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
|
||||
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
|
||||
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
|
||||
org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
|
||||
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
|
||||
org.eclipse.jdt.core.compiler.problem.nullReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
|
||||
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
|
||||
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
|
||||
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
|
||||
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
|
||||
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
|
||||
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
|
||||
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
|
||||
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
|
||||
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info
|
||||
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
||||
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=17
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
package enumeration;
|
||||
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.out.println(Planet.values());
|
||||
|
||||
for (Planet planet : Planet.values()) {
|
||||
System.out.printf("%s -> %,.0f km/h%n",
|
||||
planet.name(),
|
||||
planet.bahngeschwindigkeit());
|
||||
}
|
||||
|
||||
System.out.println(Planet.MERKUR.toString());
|
||||
System.out.println(Planet.MERKUR.name());
|
||||
System.out.println(Planet.JUPITER.toString());
|
||||
System.out.println(Planet.JUPITER.name());
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package enumeration;
|
||||
|
||||
public enum Operation {
|
||||
|
||||
ADDITION {
|
||||
public double anwenden(double op1, double op2) {
|
||||
return op1 + op2;
|
||||
}
|
||||
},
|
||||
SUBTRAKTION {
|
||||
public double anwenden(double op1, double op2) {
|
||||
return op1 - op2;
|
||||
}
|
||||
},
|
||||
MULTIPLIKATION {
|
||||
public double anwenden(double op1, double op2) {
|
||||
return op1 * op2;
|
||||
}
|
||||
};
|
||||
|
||||
public abstract double anwenden(double op1, double op2);
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package enumeration;
|
||||
|
||||
public enum Planet {
|
||||
MERKUR(59e+6, 88), VENUS(108e+6, 225),
|
||||
ERDE(150e+6, 365), MARS(228e+6, 1.9*365),
|
||||
JUPITER(778e+6, 11.9*365), SATURN(1427e+6, 29.5*365),
|
||||
URANUS(2870e+6, 84*365), NEPTUN(4497e+6, 165*365);
|
||||
|
||||
private final double entfernungsonne;
|
||||
private final double umlaufzeit;
|
||||
|
||||
private Planet(double entfernungsonne, double umlaufzeit) {
|
||||
this.entfernungsonne = entfernungsonne;
|
||||
this.umlaufzeit = umlaufzeit;
|
||||
}
|
||||
|
||||
public double bahngeschwindigkeit() {
|
||||
return 2 * entfernungsonne * Math.PI / umlaufzeit / 24;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name() + " ist der " + (ordinal() + 1) + " Planet im Sonnensystem.";
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package enumeration;
|
||||
|
||||
public class Rechner {
|
||||
|
||||
public double rechne(double op1, double op2, Operation operation) {
|
||||
return operation.anwenden(op1, op2);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Rechner r = new Rechner();
|
||||
|
||||
double summe = r.rechne(5, 5, Operation.ADDITION);
|
||||
double differenz = r.rechne(6, 3, Operation.SUBTRAKTION);
|
||||
double produkt = r.rechne(6, 3, Operation.MULTIPLIKATION);
|
||||
|
||||
System.out.printf("%.0f, %.0f, %.0f", summe, differenz, produkt);
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
package enumeration;
|
||||
|
||||
public enum Wochentag {
|
||||
MONTAG, DIENSTAG, MITTWOCH, DONNERSTAG, FREITAG, SAMSTAG, SONNTAG;
|
||||
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package generics;
|
||||
|
||||
public class ExtStack<T> extends SimpleStack<T> {
|
||||
|
||||
public ExtStack(int size) {
|
||||
super(size);
|
||||
}
|
||||
|
||||
/*
|
||||
* In dieser Methode passiert nichts anderes als die Ausgabe des zuletzt
|
||||
* gesetzten Wertes (in diesem Fall ein String). Das erzeugte Array wurde
|
||||
* üder den Konstruktor ExtStack angelegt, indem die Arraygröße und
|
||||
* der Datentyp in dem Konstruktoraufruf (siehe Mainmethode) übergeben wurde
|
||||
* und der Aufruf an die Superklasse SimpleStack weitergeleitet wurde.
|
||||
*/
|
||||
public T peek() {
|
||||
T wert = pop(); // Hier wird der Wert mit pop() aus dem Array geholt
|
||||
push(wert); // und in die Variable wert geschrieben
|
||||
return wert; // danach erfolgt die Rückmeldung an den Methodenaufruf
|
||||
}
|
||||
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package generics;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
var simplestack1 = new SimpleStack<String>(5);
|
||||
|
||||
simplestack1.push("Hallo");
|
||||
simplestack1.push("das ist ein Beispiel für");
|
||||
simplestack1.push("einen SimpleStack.");
|
||||
simplestack1.push("Logisch wird alles in ");
|
||||
simplestack1.push("verkehrter Reihenfolge ausgegeben.");
|
||||
|
||||
for (int i = simplestack1.getSize(); i > 0 ; i--) {
|
||||
System.out.print(simplestack1.pop() + "| |");
|
||||
}
|
||||
|
||||
var extstack1 = new ExtStack<String>(2);
|
||||
|
||||
extstack1.push("Hallo");
|
||||
extstack1.push("Hello");
|
||||
|
||||
System.out.println(extstack1.peek());
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package generics;
|
||||
|
||||
public class SimpleStack<T> {
|
||||
/*
|
||||
* Der Einsatz eines Typ-Parameters hält diese Klasse generisch und
|
||||
* ermöglicht es, dass erst in der Main der Datentyp des Arrays festgelegt
|
||||
* werden kann. Somit ist die generische Klasse in ihrer Implementierung
|
||||
* unabhängig von der Main-Klasse.
|
||||
*/
|
||||
private T[] stack;
|
||||
private int pos;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public SimpleStack(int size) {
|
||||
stack = (T[]) new Object[size];
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
public void push(T o) {
|
||||
stack[pos++] = o;
|
||||
}
|
||||
|
||||
public T pop() {
|
||||
return stack[--pos];
|
||||
|
||||
}
|
||||
/*
|
||||
* Dies ist ziemlich schlechter Programmierstiel, da für einen gut
|
||||
* funktionierenden Stack noch weitere Methoden fehlen.
|
||||
* Diese sind zum Beispiel swap(), peek() und clear(). So das es möglich
|
||||
* ist Daten zu Tauschen (swap()), Daten zu löschen (clear()) oder nach
|
||||
* Daten zu suchen (peek())
|
||||
*/
|
||||
|
||||
public int getSize () {
|
||||
// TODO Auto-generated method stub
|
||||
return pos;
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package records;
|
||||
|
||||
|
||||
public class Rechteck extends Exception{
|
||||
|
||||
record Rectangle(double laenge, double breite) {
|
||||
public Rectangle {
|
||||
if (laenge <= 0 || breite <= 0) {
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
String.format("Keine 0 oder negative Werte erlaubt."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Rectangle r = new Rectangle(4.0, 3.0);
|
||||
Rectangle r2 = new Rectangle(1.0, 2.0);
|
||||
|
||||
System.out.println("Fläche: " + r.laenge() * r.breite());
|
||||
System.out.println("Fläche2: " + r2.laenge() * r2.breite());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package records;
|
||||
|
||||
public final class RechteckOhneRecords {
|
||||
|
||||
private final double laenge;
|
||||
private final double breite;
|
||||
|
||||
public RechteckOhneRecords(double laenge, double breite) {
|
||||
this.laenge = laenge;
|
||||
this.breite = breite;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
RechteckOhneRecords r = new RechteckOhneRecords(4, 3);
|
||||
|
||||
System.out.println("Fläche = " + r.laenge() * r.breite());
|
||||
}
|
||||
|
||||
private double breite() {
|
||||
// TODO Auto-generated method stub
|
||||
return laenge;
|
||||
}
|
||||
|
||||
private double laenge() {
|
||||
// TODO Auto-generated method stub
|
||||
return breite;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
package Crypter;
|
||||
|
||||
|
||||
/**
|
|
@ -1,4 +1,3 @@
|
|||
package Crypter;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
|
@ -1,4 +1,3 @@
|
|||
package Crypter;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
|
@ -1,27 +1,4 @@
|
|||
package pr2.enums.schnick;
|
||||
|
||||
public enum Move {
|
||||
|
||||
STEIN, PAPIER, SCHERE;
|
||||
|
||||
public static boolean checkMove(String c, String s) {
|
||||
|
||||
String move = c + s;
|
||||
|
||||
if (move == "rp"){
|
||||
return false;
|
||||
} else if (move == "pr") {
|
||||
return true;
|
||||
} else if (move == "rs") {
|
||||
return false;
|
||||
} else if (move == "sr") {
|
||||
return true;
|
||||
} else if (move == "ps") {
|
||||
return false;
|
||||
} else {
|
||||
return true; // sp
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,68 +8,4 @@ import java.util.Scanner;
|
|||
*/
|
||||
public class SchnickSchnackSchnuck {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String c = "";
|
||||
String s = "";
|
||||
int spielerKonto = 0;
|
||||
int computerKonto = 0;
|
||||
int int_rand = 0;
|
||||
Random rand = new Random();
|
||||
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
|
||||
System.out.println("Start Runde: " + i);
|
||||
|
||||
|
||||
for (int j = 0; j < 1000000; j++) {
|
||||
|
||||
int_rand = rand.nextInt(3000);
|
||||
}
|
||||
if (int_rand < 1000) {
|
||||
c = "r";
|
||||
} else if (int_rand == 2000) {
|
||||
c = "p";
|
||||
} else {
|
||||
c = "s";
|
||||
}
|
||||
|
||||
Scanner eingabe = new Scanner(System.in);
|
||||
|
||||
System.out.println("Der Spieler trifft seine Auswahl: r (STEIN)" + " p (PAPIER) s (SCHERE) ");
|
||||
s = eingabe.next();
|
||||
|
||||
Boolean rückgabe = Move.checkMove(c, s);
|
||||
|
||||
if (rückgabe == false) {
|
||||
spielerKonto++;
|
||||
} else if (rückgabe){
|
||||
computerKonto++;
|
||||
}
|
||||
|
||||
if (spielerKonto > computerKonto) {
|
||||
System.out.println(
|
||||
"Der Spieler hat " + spielerKonto + " der " + "Computer hat " + computerKonto + " Punkte.");
|
||||
} else if (computerKonto > spielerKonto) {
|
||||
System.out.println(
|
||||
"Der Computer hat " + computerKonto + " der " + "Spieler hat " + spielerKonto + " Punkte.");
|
||||
} else {
|
||||
System.out.println("Beide habe bisher " + computerKonto + " Punkte.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
System.out.println("Spielende: ");
|
||||
System.out.println("Der Spieler hat " + spielerKonto + " Punkte.");
|
||||
System.out.println("Der Computer hat " + computerKonto + " Punkte.");
|
||||
if (spielerKonto == computerKonto) {
|
||||
System.out.println("Das Spiel endet unentschieden.");
|
||||
} else if (spielerKonto > computerKonto) {
|
||||
System.out.println("Der Spieler hat gewonnen.");
|
||||
} else {
|
||||
System.out.println("Der Computer hat gewonnen.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,22 +1,7 @@
|
|||
package pr2.enums.singleton;
|
||||
|
||||
public enum MyEnum {
|
||||
A(100),
|
||||
B(200),
|
||||
C(300);
|
||||
|
||||
private final int a;
|
||||
|
||||
private MyEnum(int a) {
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
public int getZahl() {
|
||||
return a;
|
||||
}
|
||||
|
||||
public String toZahl() {
|
||||
return " " + a + " ";
|
||||
}
|
||||
|
||||
enum MyEnum {
|
||||
A,
|
||||
B,
|
||||
C;
|
||||
}
|
||||
|
|
|
@ -1,41 +1,8 @@
|
|||
package pr2.enums.singleton;
|
||||
|
||||
|
||||
|
||||
public class SingletonBeweis {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.out.println(MyEnum.A);
|
||||
System.out.println(MyEnum.B);
|
||||
System.out.println(MyEnum.C);
|
||||
|
||||
MyEnum zahl = MyEnum.A;
|
||||
System.out.println(zahl.getZahl());
|
||||
System.out.println(MyEnum.A.getZahl() == 100);
|
||||
|
||||
|
||||
MyEnum a = MyEnum.A;
|
||||
MyEnum b = MyEnum.B;
|
||||
MyEnum c = MyEnum.C;
|
||||
|
||||
|
||||
System.out.println("Ausgabe über String:");
|
||||
System.out.println(a.toZahl());
|
||||
System.out.println(b.toZahl());
|
||||
System.out.println(c.toZahl());
|
||||
System.out.println("Ausgabe über int:");
|
||||
System.out.println(a.getZahl());
|
||||
System.out.println(b.getZahl());
|
||||
System.out.println(c.getZahl());
|
||||
|
||||
System.out.println("MyEnum.values() gibt die Referenz des erstellten "
|
||||
+ "Arrays zurück. Die Enum-Aufzählung funktioniert nur mit "
|
||||
+ "einer forEach-Schleife.");
|
||||
System.out.println(MyEnum.values());
|
||||
|
||||
for (MyEnum einmal : MyEnum.values()) {
|
||||
System.out.printf("%2s", einmal);
|
||||
}
|
||||
// TODO: Singleton-Eigenschaft zeigen
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ package pr2.generics.einfach;
|
|||
/**
|
||||
* Eine einfache, verkettete Liste.
|
||||
*/
|
||||
public class Liste<T> {
|
||||
public class Liste {
|
||||
|
||||
/** Referenz auf den ersten Knoten. */
|
||||
private ListeNode first;
|
||||
|
@ -19,12 +19,11 @@ public class Liste<T> {
|
|||
/**
|
||||
* Fügt ein neues Element an das Ende der Liste an.
|
||||
*
|
||||
* @param i das Element
|
||||
* @param data das Element
|
||||
*/
|
||||
public void add(String i) {
|
||||
public void add(Object data) {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ListeNode nextNode = new ListeNode(i);
|
||||
ListeNode nextNode = new ListeNode(data);
|
||||
|
||||
if (current == null) {
|
||||
// Liste komplett leer
|
||||
|
@ -32,7 +31,7 @@ public class Liste<T> {
|
|||
current = nextNode;
|
||||
}
|
||||
else {
|
||||
current.setNext(nextNode);
|
||||
current.next = nextNode;
|
||||
current = nextNode;
|
||||
}
|
||||
}
|
||||
|
@ -43,18 +42,17 @@ public class Liste<T> {
|
|||
* @param index Index, beginnend bei 0.
|
||||
* @return Das Element oder {@code null}, wenn es nicht gefunden wurde.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public String get(int index) {
|
||||
public Object get(int index) {
|
||||
int count = 0;
|
||||
T node = (T) first;
|
||||
ListeNode node = first;
|
||||
|
||||
while ((node != null) && (count < index)) {
|
||||
node = ((ListeNode<T>) node).getNext();
|
||||
node = node.next;
|
||||
count++;
|
||||
}
|
||||
|
||||
if ((count == index) && (node != null)) {
|
||||
return ((ListeNode<T>) node).getData();
|
||||
return node.data;
|
||||
}
|
||||
else {
|
||||
// index does not exist
|
||||
|
@ -77,18 +75,13 @@ public class Liste<T> {
|
|||
*/
|
||||
public int size() {
|
||||
int count = 0;
|
||||
T node = (T) first;
|
||||
ListeNode node = first;
|
||||
|
||||
while (node != null) {
|
||||
node = (T) ((ListeNode) node).getNext();
|
||||
node = node.next;
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public void add(int i) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,31 +3,20 @@ package pr2.generics.einfach;
|
|||
/**
|
||||
* Interne Repräsentation der Knoten in der Liste.
|
||||
*/
|
||||
class ListeNode<E> {
|
||||
class ListeNode {
|
||||
|
||||
/** Daten. */
|
||||
String data;
|
||||
Object data;
|
||||
|
||||
/** Referenz auf den nächsten Knoten. */
|
||||
E next;
|
||||
ListeNode next;
|
||||
|
||||
/**
|
||||
* Legt einen neuen Knoten an.
|
||||
*
|
||||
* @param data daten, die gespeichert werden
|
||||
*/
|
||||
protected ListeNode(String data) {
|
||||
this.setData(data);
|
||||
}
|
||||
public E getNext() {
|
||||
return next;
|
||||
}
|
||||
public void setNext(E next) {
|
||||
this.next = next;
|
||||
}
|
||||
public void setData(String data) {
|
||||
ListeNode(Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class ListeTest {
|
|||
|
||||
l.add("Hallo");
|
||||
assertEquals(1, l.size());
|
||||
l.add( "");
|
||||
l.add("Hugo");
|
||||
assertEquals(2, l.size());
|
||||
l.add("Peter");
|
||||
l.add("Alfons");
|
||||
|
@ -37,7 +37,7 @@ public class ListeTest {
|
|||
*/
|
||||
@Test
|
||||
void testGet() {
|
||||
Liste<String> l = new Liste<String>();
|
||||
Liste l = new Liste();
|
||||
l.add("Hallo");
|
||||
l.add("Hugo");
|
||||
l.add("Peter");
|
||||
|
|
|
@ -2,17 +2,17 @@ package pr2.generics.pair;
|
|||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
var note1 = new Pair<String, Integer>("Peter", 1);
|
||||
var note2 = new Pair<String, Integer>("Frank", 3);
|
||||
var note3 = new Pair<String, Integer>("Sabine", 1);
|
||||
|
||||
var name = new Pair<String, String>("Peter", "Meier");
|
||||
|
||||
System.out.printf("%s:%d\n", note1.getFirst(), note1.getSecond());
|
||||
System.out.printf("%s:%d\n", note2.getFirst(), note1.getSecond());
|
||||
System.out.printf("%s:%d\n", note3.getFirst(), note1.getSecond());
|
||||
|
||||
System.out.printf("%s %s\n", name.getFirst(), name.getSecond());
|
||||
// TODO: Einkommentieren
|
||||
// var note1 = new Pair<String, Integer>("Peter", 1);
|
||||
// var note2 = new Pair<String, Integer>("Frank", 3);
|
||||
// var note3 = new Pair<String, Integer>("Sabine", 1);
|
||||
//
|
||||
// var name = new Pair<String, String>("Peter", "Meier");
|
||||
//
|
||||
// System.out.printf("%s:%d\n", note1.getFirst(), note1.getSecond());
|
||||
// System.out.printf("%s:%d\n", note2.getFirst(), note1.getSecond());
|
||||
// System.out.printf("%s:%d\n", note3.getFirst(), note1.getSecond());
|
||||
//
|
||||
// System.out.printf("%s %s\n", name.getFirst(), name.getSecond());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,5 @@
|
|||
package pr2.generics.pair;
|
||||
|
||||
public class Pair<K, V> {
|
||||
|
||||
private K data1;
|
||||
private V data2;
|
||||
|
||||
public Pair(K data1, V data2) {
|
||||
this.data1 = data1;
|
||||
this.data2 = data2;
|
||||
public class Pair {
|
||||
|
||||
}
|
||||
|
||||
public K getFirst() {
|
||||
return data1;
|
||||
}
|
||||
|
||||
public V getSecond() {
|
||||
return data2;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue