weitere Übungen zu Enums
parent
d128ea407b
commit
267f4b0af0
|
@ -1,8 +1,110 @@
|
||||||
eclipse.preferences.version=1
|
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.codegen.targetPlatform=17
|
||||||
org.eclipse.jdt.core.compiler.compliance=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.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.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.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.release=disabled
|
||||||
org.eclipse.jdt.core.compiler.source=17
|
org.eclipse.jdt.core.compiler.source=17
|
||||||
|
|
|
@ -1,4 +1,27 @@
|
||||||
package pr2.enums.schnick;
|
package pr2.enums.schnick;
|
||||||
|
|
||||||
public enum Move {
|
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,4 +8,68 @@ import java.util.Scanner;
|
||||||
*/
|
*/
|
||||||
public class SchnickSchnackSchnuck {
|
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,7 +1,22 @@
|
||||||
package pr2.enums.singleton;
|
package pr2.enums.singleton;
|
||||||
|
|
||||||
enum MyEnum {
|
public enum MyEnum {
|
||||||
A,
|
A(100),
|
||||||
B,
|
B(200),
|
||||||
C;
|
C(300);
|
||||||
|
|
||||||
|
private final int a;
|
||||||
|
|
||||||
|
private MyEnum(int a) {
|
||||||
|
this.a = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getZahl() {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toZahl() {
|
||||||
|
return " " + a + " ";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,41 @@
|
||||||
package pr2.enums.singleton;
|
package pr2.enums.singleton;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class SingletonBeweis {
|
public class SingletonBeweis {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO: Singleton-Eigenschaft zeigen
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue