Update of exercises
parent
08d09ae1b8
commit
b588ff87f2
|
@ -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.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -65,3 +65,4 @@ public final class Zahlenraten {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -87,4 +87,3 @@ public class Liste<T> {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,4 +27,3 @@ class ListeNode<T> {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,4 +51,3 @@ public class CodingStandard {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -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;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
|
@ -14,3 +14,4 @@ public class Futterstelle {
|
||||||
tier.fuettern();
|
tier.fuettern();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -37,3 +37,4 @@ public final class ZooSimulation {
|
||||||
System.out.println(tier);
|
System.out.println(tier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -50,3 +50,4 @@ public class Wuerfel {
|
||||||
|
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue