1 / 7

Übung Softwareentwicklung 2 für Wirtschaftsinformatik

Übung Softwareentwicklung 2 für Wirtschaftsinformatik. UE03 Example "Snowman". Beispiel Snowman. Erstellen Sie die notwendigen Klassen um einen Schneemann zu zeichnen. Der Schneemann soll auf Basis von Kreisen und Rechtecken zusammengesetzt gezeichnet werden.

geona
Télécharger la présentation

Übung Softwareentwicklung 2 für Wirtschaftsinformatik

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Übung Softwareentwicklung 2für Wirtschaftsinformatik UE03Example "Snowman"

  2. Beispiel Snowman • Erstellen Sie die notwendigen Klassen um einen Schneemann zu zeichnen. Der Schneemann soll auf Basis von Kreisen und Rechtecken zusammengesetzt gezeichnet werden. • Zum Zeichnen kann man die vorgegebene Klasse Window und die Klassenmethoden Window.fillRectangle() bzw. Window.fillCircle() SE2UE_00 - 2

  3. Beispiel Snowman Hut: zusammengesetzt aus 2 Rechtecken Körper setz sich zusammen aus: Oberkörper (einem Kreis), linke Hand (einem Rechteck), rechte Hand, linker Fuß, rechter Fuß Schneemann: setzt sich zusammen aus Hut + Kopf (Kreis) + Körper SE2UE_00 - 3

  4. Beispiel Snowman * elems GraphObject draw() composite pattern GraphComposite GraphPrimitive GraphObject[] elems int x, y draw() : void getX() : int getY() : int Circle Rectangle int r int w, h getW() : int getH() : int draw() : void getR() : int draw() : void SE2UE_00 - 4

  5. Klassen: GraphObject, GraphPrimitive, GraphComposite abstract public class GraphObject { abstract public void draw(); } abstract public class GraphPrimitive extends GraphObject { private int x; private int y; public GraphPrimitive(int x, int y) { this.x = x; this.y = y; } protected int getX() { return x; } protected int getY() { return y; } } public class GraphCompositeextends GraphObject { private GraphObject[] elems; public GraphComposite(GraphObject[] elems) { this.elems = elems; } public void draw() { for (int i = 0; i < elems.length; i++) { elems[i].draw(); } } } SE2UE_00 - 5

  6. Klassen: GraphObject, GraphPrimitive, GraphComposite abstract public class GraphPrimitive { …… } class Rectangle extends GraphPrimitive { private int w; int h; public Rectangle(int x, int y, int w, int h) { super(x, y); this.w = w; this.h = h; } protected int getW() { return w; } protected int getH() { return h; } public void draw() { Window.fillRectangle(getX(), getY(), getW(), getH(), Color.LIGHT_GRAY); } } public class Circle extends GraphPrimitive { private int r; public Circle(int x, int y, int r) { super(x, y); this.r = r; } protected int getR() { return r; } public void draw() { Window.fillCircle(getX(), getY(), getR(), Color.LIGHT_GRAY); } } SE2UE_00 - 6

  7. Klasse: Snowman package graphical; import inout.Window; public class Snowman { public static void main(String args[]) { GraphObject hut1 = new Rectangle(130, 120, 40, 10); GraphObject hut2 = new Rectangle(140, 90, 20, 30); GraphComposite hut = new GraphComposite( new GraphObject[] {hut1, hut2}); Rectangle beinL = new Rectangle(100, 300, 45, 100); Rectangle beinR = new Rectangle(155, 300, 45, 100); Circle body = new Circle(150, 250, 60); Circle kopf = new Circle(150, 160, 30); Rectangle armL = new Rectangle(60, 210, 40, 30); Rectangle armR = new Rectangle(200, 210, 40, 30); GraphComposite koerper = new GraphComposite(new GraphObject[] { body, armL, armR, beinR, beinL}); GraphComposite snowMan = new GraphComposite(new GraphObject[] {koerper, kopf, hut}); Window.open(); snowMan.draw(); } } SE2UE_00 - 7

More Related