/* Aufgabe1.java */ import java.awt.*; import java.applet.*; /* * @author Prof. Juergen Sauer */ public class Aufgabe1 extends Applet { static final int N = 8; static final int GROESSE = 40; static int x_offset, y_offset; static int qx[] = { 4, 8, 32, 36, 31, 28, 24, 20, 16, 12, 9, 4, }; static int qy[] = { 19, 34, 34, 19, 24, 13, 22, 4, 22, 13, 24, 19, }; static int qxx[] = { 8, 17, 20, 23, 32, }; static int qyy[] = { 31, 31, 27, 31, 31, }; Dimension d; public void init() { d = getSize(); } public void paint(Graphics g) { holOffsets(); zeichneBrett(g); zeichneAlleDamen(g); } void holOffsets() { x_offset = (d.width - (N * GROESSE)) / 2; y_offset = (d.height- (N * GROESSE)) / 2 - 10; } void zeichneBrett(Graphics g) { g.setColor( Color.lightGray ); g.fillRect( 0, 0, d.width, d.height ); g.setColor( Color.lightGray ); g.draw3DRect( x_offset-2, y_offset-2, N*GROESSE+3, N*GROESSE+3, true ); g.draw3DRect( x_offset-3, y_offset-3, N*GROESSE+5, N*GROESSE+5, true ); g.draw3DRect( x_offset-4, y_offset-4, N*GROESSE+7, N*GROESSE+7, true ); for( int j=0; j < N; j++ ) { for( int i=0; i < N; i++ ) { if ((i + j) % 2 == 1) g.setColor(Color.red); else g.setColor(Color.lightGray); g.fillRect( x_offset + i*GROESSE, y_offset + j*GROESSE, GROESSE, GROESSE ); } } } void zeichneAlleDamen(Graphics g) { for( int i = 0; i < N; i++ ) { zeichneEineDame(g, x_offset+GROESSE*i, y_offset+GROESSE*(N - i - 1) ); } } void zeichneEineDame(Graphics g, int x, int y) { g.translate( x, y ); g.setColor( Color.white ); g.fillPolygon( qx, qy, qx.length ); g.setColor( Color.black ); g.drawPolygon( qx, qy, qx.length ); g.drawPolygon( qxx, qyy, qxx.length ); g.translate( -x, -y ); } } /* Aufgabe2.java */ /* * @author Benjamin Kormann */ class InitVal { boolean a; byte b; char c; double d; float e; int f; long g; short h; public InitVal() { System.out.println("type\tinit"); System.out.println("-------------"); System.out.println("boolean\t" + a); System.out.println("byte\t" + b); System.out.println("char\t" + c); System.out.println("double\t" + d); System.out.println("float\t" + e); System.out.println("int\t" + f); System.out.println("long\t" + g); System.out.println("short\t" + h); } } public class Aufgabe2 { public static void main(String args[]) { new InitVal(); } } /* Aufgabe4.java */ /* * @author Prof. Juergen Sauer */ class Primzahlen { private int start; public int zaehler = 100; // Konstruktor mit einem Argument public Primzahlen(int sta) { start = sta; } private boolean istPrimzahl(int p) { for (int i = 2; i < (p / 2); i++) { if ( (i * (p / i)) == p) return false; } return true; } public void erzeuge(int feld[]) { int sta = start; int z = zaehler; int idx = 0; while (z > 0) { if (istPrimzahl(sta)) { feld[idx++] = sta; z--; } if (sta == 2) sta++; else sta = sta + 2; } } } public class Aufgabe4 { public static void main(String args[]) { Primzahlen p; int feldP[]; int laenge; int sta = 2; int zaehler = 0; laenge = args.length; p = new Primzahlen(sta); if (laenge > 0) { zaehler = Integer.parseInt(args[0]); p.zaehler = zaehler; } feldP = new int[p.zaehler]; p.erzeuge(feldP); for (int i = 0; i < p.zaehler; i++) { System.out.print(feldP[i] + " "); if (i == 0) continue; if ((i % 12) == 0) { System.out.println(); } } } }