Aufgabe 22.2.11 Tagesausflug ============================ int x = 10; // x-Position int y = 150; // y-Position int b = 50; // Breite int a = 10; // Abstand g.setColor(Color.RED); // ROT leuchtet g.fillOval(x+a, y+a, b, b); g.setColor(Color.GREEN); // GRÜN leuchtet g.fillOval(x+a, y+b+a+a, b, b); g.setColor(Color.BLACK); // Ampelrahmen g.drawRect(x, y, b+a+a, (b+a)*2+a); g.drawOval(x+a, y+a, b, b); g.drawOval(x+a, y+b+a+a, b, b); Aufgabe 22.2.13 Zylinderberechnung (Teil 1) =========================================== int x = 50; // x-Position int y = 150; // y-Position int b = 100; // Breite int h = 25; // Höheneinheit g.setColor(Color.WHITE); g.fillRect(x, y+h, b, 4*h); g.setColor(Color.BLACK); g.drawRect(x, y+h, b, 4*h); g.setColor(Color.WHITE); g.fillOval(x, y, b, 2*h); g.fillOval(x, y+4*h, b, 2*h); g.setColor(Color.BLACK); g.drawOval(x, y, b, 2*h); g.drawOval(x, y+4*h, b, 2*h); g.drawString("Zylinder", x+h, y+h); Aufgabe 22.2.19 Würfelstatistik =============================== int x = 100; // x-Position int y = 100; // y-Position int p = 10; // Breite Punkt int a = 2; // Abstand zwischen Punkten int b = 38; // Breite des Würfels int w = 10; // Winkel // Würfel g.setColor(Color.BLACK); g.fillRoundRect(x, y, b, b, w, w); // Punkte g.setColor(Color.WHITE); g.fillOval(x+a , y+a , p, p); g.fillOval(x+3*a+2*p , y+a , p, p); g.fillOval(x+a , y+2*a+p , p, p); g.fillOval(x+2*a+p , y+2*a+p , p, p); g.fillOval(x+3*a+2*p , y+2*a+p , p, p); g.fillOval(x+a , y+3*a+2*p , p, p); g.fillOval(x+3*a+2*p , y+3*a+2*p , p, p); Aufgabe 22.2.22 Nadelbaum ========================= int x = 100; // Start X-Koordinate int y = 100; // Start y-Koordinate int b = 15; int[] aX = new int[3]; int[] aY = new int[3]; aX[0] = x-2*b; aX[1] = x; aX[2]=x+2*15; aY[0] = y+2*b*2; aY[1] = y+2*b; aY[2]=aY[0]; g.fillPolygon(aX, aY, 3); aX[0] = x-3*b; aX[1] = x; aX[2]=x+3*15; aY[0] = y+3*b*2; aY[1] = y+3*b; aY[2]=aY[0]; g.fillPolygon(aX, aY, 3); aX[0] = x-4*b; aX[1] = x; aX[2]=x+4*15; aY[0] = y+4*b*2; aY[1] = y+4*b; aY[2]=aY[0]; g.fillPolygon(aX, aY, 3); // Stamm zeichnen g.fillRect(x-b, y+4*b*2, b*2, b*2); Aufgabe 22.2.28 Schachspiel =========================== char[][] stellung = // Grundstellung { {'t', 'b', ' ', ' ', ' ', ' ', 'B', 'T'}, {'s', 'b', ' ', ' ', ' ', ' ', 'B', 'S'}, {'l', 'b', ' ', ' ', ' ', ' ', 'B', 'L'}, {'d', 'b', ' ', ' ', ' ', ' ', 'B', 'D'}, {'k', 'b', ' ', ' ', ' ', ' ', 'B', 'K'}, {'l', 'b', ' ', ' ', ' ', ' ', 'B', 'L'}, {'s', 'b', ' ', ' ', ' ', ' ', 'B', 'S'}, {'t', 'b', ' ', ' ', ' ', ' ', 'B', 'T'}, }; // Stellung aus alten Zügen rekonstruieren for (int i=0; i<=eingabeIndex; i++) { String zug = _Eingabe.getString(i); if (ziehen(zug, stellung)) { println(zug); } else // Zug löschen, wenn unzulässig { _Eingabe.removeEingabe(i); } } // Stellung anzeigen showStellung(g, stellung); Aufgabe 22.2.29 Tic-Tac-Toe =========================== int[][] stellung = {{0,0,0},{0,0,0},{0,0,0}}; // Alle Züge rekonstruieren // UND Spielerzug ausführen int i = 0; do { String zug = _Eingabe.getString(i); if (ziehen(zug,stellung,i%2)) println(zug); else _Eingabe.removeEingabe(i); i=i+1; } while( i<=_Eingabe.getIndex() && gewonnen(stellung) == -1 ); // Rechner ist am Zug if ( _Eingabe.getIndex()%2 == 0 && gewonnen(stellung) == -1 ) { String zug = bestimmeZug(stellung); ziehen(zug, stellung, 1); println(zug); _Eingabe.addEingabe(zug); // Zug speichern } // Kontrolle Spielende switch (gewonnen(stellung)) { case 0: println ("WEISS\ngewinnt");break; case 1: println ("SCHWARZ\ngewinnt");break; case 2: println ("UNENTSCHIEDEN");break; } // Rekonstruierte aktuelle Stellung anzeigen showStellung(g, stellung); Aufgabe 22.3.11 Kürzester Weg ============================= char[][] stellung = { {'S', ' ', ' ', ' ', 'H', ' ', ' ', ' '}, {'H', ' ', 'H', ' ', 'H', ' ', 'H', ' '}, {' ', ' ', 'H', ' ', 'H', ' ', 'H', ' '}, {' ', 'H', 'H', 'H', 'H', ' ', 'H', ' '}, {' ', ' ', 'H', ' ', ' ', ' ', 'H', ' '}, {'H', ' ', 'H', ' ', ' ', ' ', 'H', ' '}, {' ', ' ', ' ', ' ', 'H', ' ', 'H', ' '}, {' ', ' ', ' ', ' ', 'H', ' ', ' ', 'Z'}, }; Aufgabe 22.4.4b Würfel (Teil 3) =============================== Wuerfel.setStandardFarbe(Color.BLACK); Wuerfel w1 = new Wuerfel(); Wuerfel w2 = new Wuerfel(100, 50); Wuerfel.setStandardFarbe(Color.GREEN); Wuerfel w3 = new Wuerfel(150, 50); Wuerfel w4 = new Wuerfel(200, 50, Color.BLUE); Aufgabe 22.4.4d Gehalt (Teil 1) =============================== Gehalt g1 = new Gehalt(); Gehalt.setUntergrenze(1000.0d); Gehalt g2 = new Gehalt(500.0d); Gehalt g3 = new Gehalt(4321.0d); Gehalt g4 = new Gehalt(9999.0d); Aufgabe 22.4.5a Wrapper-Klassen =============================== public class Start { public static int iAdd (int i) { return i + 1; } public static Integer wAdd (Integer iW) { return iW + 1; } public static void main(String[] args) { int i = 10; Integer iW = 10; System.out.println("iAdd: " + iAdd(i)); System.out.println("wAdd: " + wAdd(iW)); System.out.println("i: " + i); System.out.println("iW: " + iW); } } Aufgabe 22.4.5d Operator ======================== public static void main(String[] args) { double a = 4.56d; double b = 1.23d; System.out.println(ber(Operator.ADD, a, b)); System.out.println(ber(Operator.SUB, a, b)); System.out.println(ber(Operator.MUL, a, b)); System.out.println(ber(Operator.DIV, a, b)); } Aufgabe 22.4.6b Variablen aus anderen Paketen ============================================= package paketA; public class KlasseA { public int d = 13; public static int e = 14; } package paketB; public class Start { int a = 10; static int b = 11; public static void main (String[] args) { int c = 12; // Bitte ab hier ergänzen ... } } Aufgabe 22.5.1a Kuchen (Teil 4) =============================== Baecker b1 = new Baecker(); Baecker b2 = new Baecker("Ernst","Klein"); Kuchen k1 = b1.macheKuchen(); Kuchen k2 = b1.macheKuchen(200,150,2,100,16); Kuchen k3 = b1.macheKuchen(250,200,3,150,12); Kuchen k4 = b2.macheKuchen(); b1.esseStuecke(k4, 2); b2.esseStuecke(k2, 1); b2.essenFertig(); b2.esseStuecke(k3, 2); b2.essenFertig(); k1.showObjektVar(); k2.showObjektVar(); k3.showObjektVar(); k4.showObjektVar(); b1.showObjektVar(); b2.showObjektVar(); Aufgabe 22.5.1b Patient (Teil 4) ================================ Arzt a1 = new Arzt("Eva", "Klein"); Arzt a2 = new Arzt("Udo", "Gross"); Patient p1 = new Patient(); Patient p2 = new Patient("Klaus", "Schmidt",'m',1973,2.10d,95.0d,false, a1); p1.showObjektVar(); p2.showObjektVar(); p1.erstUntersuchung(); p1.untersuchung(a1); p2.erstUntersuchung(); p2.untersuchung(a2); a2.untersucht(p1); a1.showObjektVar(); a2.showObjektVar(); Aufgabe 22.5.2a Kuchen (Teil 5) =============================== Kuchen k1 = new Kuchen(200, 150, 2, 100, 16); Torte t1 = new Torte(); Torte t2 = new Torte(k1, 2, "Quarkcreme"); Torte t3 = new Torte(300, 300, 3, 125, 12, 4, "Sahnecreme"); k1.showObjektVar(); t1.showObjektVar(); t2.showObjektVar(); t3.showObjektVar(); t1.essen(3); t1.showObjektVar(); Aufgabe 22.5.2b Würfel (Teil 4) =============================== // erster Wurf Wurf w = new Wurf(); w.drawObjekt(g); w.ungueltig(2); w.ungueltig(3); w.setYPos(100); w.drawObjekt(g); // zweiter Wurf w.wuerfeln(); w.setYPos(170); w.drawObjekt(g); w.ungueltig(0); w.ungueltig(4); w.setYPos(220); w.drawObjekt(g); // dritter Wurf w.wuerfeln(); w.setYPos(290); w.drawObjekt(g); Aufgabe 22.5.2d Fahrzeug (Teil 3) ================================= Fahrzeug f = new Fahrzeug(); f.showObjektVar(); // Ein Motortyp ... MotorTyp mt1 = new MotorTyp(81,1598,4,"Diesel",3.9d); // ... verbaut bei zwei verschiedenen Fahrzeugtypen FahrzeugTyp ft1 = new FahrzeugTyp ("Audi","A3", mt1); FahrzeugTyp ft2 = new FahrzeugTyp ("Seat","Leon",mt1); Fahrzeug f1 = new Fahrzeug("B-KA-123", 2018, ft1); Fahrzeug f2 = new Fahrzeug("BO-ND-007", 2017, ft1); Fahrzeug f3 = new Fahrzeug("DO-SE-321", 2012, ft2); Fahrzeug f4 = new Fahrzeug("SO-S-112", 2015, ft2); f1.showObjektVar(); f2.showObjektVar(); f3.showObjektVar(); f4.showObjektVar(); Aufgabe 22.5.2a Patient (Teil 5) ================================ Patient p1 = new Patient(); Patient p2 = new Patient("Uwe", "Groß", 'm', 1995, 1.82d, 75.0d, false); Patient p3 = new Patient("Ute", "Ax", 'w', 1965, 1.75d, 62.0d, true); Patient p4 = new Patient("Klaus", "Schmidt", 'm', 1973, 2.10d, 95.0d, false); Zimmer z1 = new Zimmer(); Zimmer z2 = new Zimmer("EG-02",null,null,18); z1.showObjektVar(); z2.showObjektVar(); z1.setFensterBett(p1); z1.setBett(p2); z2.setTuerBett(p3); z2.setBett(p4); z1.showObjektVar(); z2.showObjektVar(); Aufgabe 22.6.2e Formen (Teil 1):_umgebung / Teilabschnitt 5: Baer Array ======================================================================= AbsForm[] baer = { new Kreis ( 160, 100, 50, Color.ORANGE), //Kopf new Kreis ( 150, 90, 10, Color.BLUE), //Augen new Kreis ( 170, 90, 10, Color.BLUE), new Kreis ( 135, 76, 20, Color.ORANGE), //Ohren new Kreis ( 185, 76, 20, Color.ORANGE), new Kreis ( 120, 130, 30, Color.ORANGE), //Arme new Kreis ( 200, 130, 30, Color.ORANGE), new Kreis ( 120, 170, 30, Color.ORANGE), //Beine new Kreis ( 200, 170, 30, Color.ORANGE), new Quadrat( 160, 110, 14, Color.RED), //Mund new Quadrat( 160, 150, 50, Color.ORANGE) //Bauch }; Aufgabe 22.6.2e Formen (Teil 1):_umgebung / Teilabschnitt 6: Maus Array ======================================================================= AbsForm[] maus = { new Dreieck( 160, 70, 70, Color.GRAY), //Kopf new Kreis ( 150, 75, 10, Color.BLUE), //Augen new Kreis ( 170, 75, 10, Color.BLUE), new Kreis ( 128, 55, 40, Color.GRAY), //Ohren new Kreis ( 192, 55, 40, Color.GRAY), new Kreis ( 120, 130, 30, Color.GRAY), //Arme new Kreis ( 200, 130, 30, Color.GRAY), new Kreis ( 120, 170, 30, Color.GRAY), //Beine new Kreis ( 200, 170, 30, Color.GRAY), new Quadrat( 160, 90, 10, Color.RED), //Mund new Dreieck( 160, 113, 30, Color.GRAY), //Hals new Quadrat( 160, 150, 50, Color.GRAY), //Bauch }; Aufgabe 22.6.2e Formen (Teil 1):_umgebung / Teilabschnitt 7: Ist-Teil-Beziehung =============================================================================== Tier[] tier = { new Tier(0, 0, baer), new Tier(150, 0, maus) // Darstellung der Maus um 150 Pixel nach rechts verschoben. }; for (Tier t: tier) { t.drawObjekt(g); } Aufgabe 22.7.1a Verkettete Liste ================================ Zug z = new Zug(5); z.addWagon(6); z.addWagon(3); z.addWagon(9); z.addWagon(4); z.addWagon(1); z.addWagon(2); z.addWagon(8); z.addWagon(0); z.addWagon(7); for (int i=0; i<10; i++) { System.out.println(z.getInhalt(i)); } Aufgabe 22.7.3a Möbel (Teil 4) ============================== Moebel hs1 = new Moebel (0, 0, Color.WHITE, 60, 220, "Hochschrank"); Moebel hs2 = new Moebel (60, 0, Color.BLUE, 30, 220, "Hochschrank"); Moebel os1 = new Moebel (90, 0, Color.WHITE, 50, 70, "Oberschrank"); Moebel os2 = new Moebel (140, 0, Color.WHITE, 50, 70, "Oberschrank"); Moebel os3 = new Moebel (190, 0, Color.WHITE, 50, 70, "Oberschrank"); Moebel os4 = new Moebel (240, 0, Color.BLUE, 30, 70, "Oberschrank"); Moebel us1 = new Moebel (210, 130, Color.WHITE, 60, 90, "Unterschrank"); Herd he1 = new Herd (90, 130, Color.WHITE, 60, 90, 100); Gefrierschrank gs1 = new Gefrierschrank(150, 130, Color.WHITE, 60, 90, true); Aufgabe 22.7.3b Baum (Teil 5) ============================= for (int i=0; i<10; i++) { garten.addBaum(new Laubbaum (i*40, 80, 2000, 15.0d, 2.0d, "rundlich", "gefiedert", "Kastanie")); garten.addBaum(new Nadelbaum(i*40, 180, 2000, 15.0d, 2.0d, "monopodial", 4)); garten.addBaum(new Obstbaum (i*40, 280, 2000, 15.0d, 2.0d, "oval", "gesägt", "Apfel", "NORMAL", "JULI")); } Aufgabe 22.10.1.b Berechne ========================== public static void main(String[] args) { System.out.println(berechne((x,y,z) -> {return x*100+y*10+z;})); System.out.println(berechne((x,y,z) -> {return x+y+z;})); System.out.println(berechne((x,y,z) -> {return x*y*z;})); System.out.println(verbinde((x,y,z) -> {return x+y+z;})); System.out.println(verbinde((x,y,z) -> {return y+x+z;})); System.out.println(verbinde((x,y,z) -> {return z+y+x;})); } Aufgabe 22.20.3 XML-Verarbeitung in Java ======================================== Hallo dies ist ein Beispiel