Update of exercises

main
Thomas Smits 2024-12-17 11:03:20 +01:00
parent 08d09ae1b8
commit b588ff87f2
14 changed files with 77 additions and 37 deletions

View File

@ -8,22 +8,6 @@ import java.util.Random;
public class Wuerfel { public class Wuerfel {
// /** 4-seitiger Würfel. */
// public static final int D4 = 4;
//
// /** 6-seitiger Würfel. */
// public static final int D6 = 6;
//
// /** 8-seitiger Würfel. */
// public static final int D8 = 8;
//
// /** 10-seitiger Würfel. */
// public static final int D10 = 10;
//
// /** 12-seitiger Würfel. */
// public static final int D12 = 13;
/** /**
* Zufallszahlengenerator. * Zufallszahlengenerator.
*/ */

View File

@ -22,3 +22,20 @@ public class WuerfelTest {
internalTestFairness(new Wuerfel(typ), typ.average()); internalTestFairness(new Wuerfel(typ), typ.average());
} }
} }
/**
* Interne Hilfsmethode, um die Fairness zu testen.
*
* @param w der zu testende Wuerfel.
* @param expected Erwartungswert.
*/
private void internalTestFairness(Wuerfel w, double expected) {
long sum = 0;
for (int i = 0; i < RUNS; i++) {
sum += w.roll();
}
double average = (double) sum / (double) RUNS;
assertEquals(expected, average, 0.1);
}
}

View File

@ -65,3 +65,4 @@ public final class Zahlenraten {
} }
} }
} }
}

View File

@ -87,4 +87,3 @@ public class Liste<T> {
return count; return count;
} }
} }

View File

@ -27,4 +27,3 @@ class ListeNode<T> {
this.data = data; this.data = data;
} }
} }

View File

@ -51,4 +51,3 @@ public class CodingStandard {
return result; return result;
} }
} }

View File

@ -9,7 +9,6 @@ package pr2.intro.javadoc;
* Objekte dieser Klasse sind imutable, d.h. sie können nach der Erzeugung * Objekte dieser Klasse sind imutable, d.h. sie können nach der Erzeugung
* nicht mehr verändert werden. * nicht mehr verändert werden.
*/ */
public class Waehrung { public class Waehrung {
/** /**

View File

@ -4,3 +4,57 @@ package pr2.strukturierung.information_hiding;
* Ein einfacher Taschenrechner. * Ein einfacher Taschenrechner.
*/ */
public class Rechner { public class Rechner {
/** Speicher des Taschenrechners. */
private double speicher;
/**
* Addiert zwei Werte und gibt das Ergebnis zurück.
*
* @param a erster Operand.
* @param b zweiter Operand.
* @return das Ergebnis.
*/
public double addiere(double a, double b) {
return a + b;
}
/**
* Subtrahiert zwei Werte und gibt das Ergebnis zurück.
*
* @param a erster Operand.
* @param b zweiter Operand.
* @return das Ergebnis.
*/
public double subtrahiere(double a, double b) {
return a - b;
}
/**
* Multipliziert zwei Werte und gibt das Ergebnis zurück.
*
* @param a erster Operand.
* @param b zweiter Operand.
* @return das Ergebnis.
*/
public double multipliziere(double a, double b) {
return a * b;
}
/**
* Gibt den gespeicherten Wert zurück.
*
* @return gespeicherter Wert.
*/
public double getSpeicher() {
return speicher;
}
/**
* Speichert den gegebenen Wert.
*
* @param wert Wert, der gespeichert werden soll.
*/
public void setSpeicher(double wert) {
speicher = wert;
}
}

View File

@ -4,15 +4,3 @@ public class Figur {
private final int flaeche; private final int flaeche;
// protected Figur() {
// /* nichts zu tun */
// }
protected Figur(int flaeche) {
this.flaeche = flaeche;
}
public int getFlaeche() {
return flaeche;
}
}

View File

@ -6,8 +6,3 @@ public class Rechteck extends Figur {
public Rechteck(int breite, int hoehe) { public Rechteck(int breite, int hoehe) {
super(breite * hoehe); super(breite * hoehe);
} }
// public Rechteck(int breite, int hoehe) {
// flaeche = breite * hoehe;
// }
}

View File

@ -14,3 +14,4 @@ public class Futterstelle {
tier.fuettern(); tier.fuettern();
} }
}

View File

@ -37,3 +37,4 @@ public final class ZooSimulation {
System.out.println(tier); System.out.println(tier);
} }
} }
}

View File

@ -31,3 +31,5 @@ public final class Spiel {
System.out.println("Statistik für alle Würfel"); System.out.println("Statistik für alle Würfel");
System.out.println(Wuerfel.statistik()); System.out.println(Wuerfel.statistik());
System.out.println(); System.out.println();
}
}

View File

@ -50,3 +50,4 @@ public class Wuerfel {
return result.toString(); return result.toString();
} }
}