From 547b2d2539ff087fbb92805e01220665dfcf0cad Mon Sep 17 00:00:00 2001
From: Martin Goik <goik@hdm-stuttgart.de>
Date: Mon, 1 Jun 2015 08:20:47 +0200
Subject: [PATCH] Adding new figure related inheritance exercise

---
 Doc/Sd1/inheritance.xml                       |  9 ++--
 P/Sd1/Figure/BaseClass/.gitignore             |  5 +++
 P/Sd1/Figure/BaseClass/pom.xml                | 45 +++++++++++++++++++
 .../de/hdm_stuttgart/mi/sd1/figure/App.java   | 12 +++++
 .../mi/sd1/figure/model/Circle.java           | 29 ++++++++++++
 .../mi/sd1/figure/model/Figure.java           | 26 +++++++++++
 .../mi/sd1/figure/model/Rectangle.java        | 38 ++++++++++++++++
 P/pom.xml                                     |  2 +
 8 files changed, 162 insertions(+), 4 deletions(-)
 create mode 100644 P/Sd1/Figure/BaseClass/.gitignore
 create mode 100644 P/Sd1/Figure/BaseClass/pom.xml
 create mode 100644 P/Sd1/Figure/BaseClass/src/main/java/de/hdm_stuttgart/mi/sd1/figure/App.java
 create mode 100644 P/Sd1/Figure/BaseClass/src/main/java/de/hdm_stuttgart/mi/sd1/figure/model/Circle.java
 create mode 100644 P/Sd1/Figure/BaseClass/src/main/java/de/hdm_stuttgart/mi/sd1/figure/model/Figure.java
 create mode 100644 P/Sd1/Figure/BaseClass/src/main/java/de/hdm_stuttgart/mi/sd1/figure/model/Rectangle.java

diff --git a/Doc/Sd1/inheritance.xml b/Doc/Sd1/inheritance.xml
index 31287b9d2..c41d3ab1b 100644
--- a/Doc/Sd1/inheritance.xml
+++ b/Doc/Sd1/inheritance.xml
@@ -41,8 +41,8 @@
               <para>Our two geometric primitives circle and rectangle will
               need a reference point (x,y) in order to allow for
               <methodname>move(...)</methodname> operations. We choose the
-              left lower corner for rectangles and the center for circles:
-              </para>
+              left lower corner for rectangles and the center for
+              circles:</para>
 
               <mediaobject>
                 <imageobject>
@@ -50,8 +50,9 @@
                 </imageobject>
               </mediaobject>
 
-              <para>We now have two more parameters <property>x</property> and
-              <property>y</property>. Implement the following inheritance
+              <para>We thus have two additional parameters
+              <property>x</property> and <property>y</property> representing
+              an object's position. Implement the following inheritance
               diagram by three <xref linkend="glo_Java"/> classes
               <classname>Figure</classname>, <classname>Circle</classname> and
               <classname>Rectangle</classname>:</para>
diff --git a/P/Sd1/Figure/BaseClass/.gitignore b/P/Sd1/Figure/BaseClass/.gitignore
new file mode 100644
index 000000000..cf5fd6bb2
--- /dev/null
+++ b/P/Sd1/Figure/BaseClass/.gitignore
@@ -0,0 +1,5 @@
+/.settings
+/target
+/.classpath
+/.project
+/A1.log
diff --git a/P/Sd1/Figure/BaseClass/pom.xml b/P/Sd1/Figure/BaseClass/pom.xml
new file mode 100644
index 000000000..d224ad673
--- /dev/null
+++ b/P/Sd1/Figure/BaseClass/pom.xml
@@ -0,0 +1,45 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>de.hdm-stuttgart.mi</groupId>
+    <artifactId>lecturenotes-pom</artifactId>
+    <version>1.0</version>
+    <relativePath>../../../pom.xml</relativePath>
+  </parent>
+
+  <groupId>de.hdm-stuttgart.de.sd1</groupId>
+  <artifactId>figure</artifactId>
+  <version>1.1</version>
+  <packaging>jar</packaging>
+
+  <name>figure</name>
+  <url>http://www.mi.hdm-stuttgart.de/freedocs</url>
+
+  <build>
+    <plugins>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <version>2.10.1</version>
+        <configuration>
+          <linksource>true</linksource>
+          <taglets>
+            <taglet>
+              <tagletClass>de.hdm_stuttgart.de.sd1.taglet.HtmlExtensionTaglet</tagletClass>
+	      <tagletArtifact>
+		<groupId>de.hdm-stuttgart.de.sd1</groupId>
+		<artifactId>taglet</artifactId>
+		<version>1.0</version>
+              </tagletArtifact>
+            </taglet>
+          </taglets>
+        </configuration>
+      </plugin>
+
+    </plugins>
+  </build>
+
+</project>
diff --git a/P/Sd1/Figure/BaseClass/src/main/java/de/hdm_stuttgart/mi/sd1/figure/App.java b/P/Sd1/Figure/BaseClass/src/main/java/de/hdm_stuttgart/mi/sd1/figure/App.java
new file mode 100644
index 000000000..31badd441
--- /dev/null
+++ b/P/Sd1/Figure/BaseClass/src/main/java/de/hdm_stuttgart/mi/sd1/figure/App.java
@@ -0,0 +1,12 @@
+package de.hdm_stuttgart.mi.sd1.figure;
+
+/**
+ * Playing with fraction objects, producing some output.
+ *
+ */
+public class App {
+  public static void main(String[] args) {
+
+    
+  }
+}
diff --git a/P/Sd1/Figure/BaseClass/src/main/java/de/hdm_stuttgart/mi/sd1/figure/model/Circle.java b/P/Sd1/Figure/BaseClass/src/main/java/de/hdm_stuttgart/mi/sd1/figure/model/Circle.java
new file mode 100644
index 000000000..ccb81c91f
--- /dev/null
+++ b/P/Sd1/Figure/BaseClass/src/main/java/de/hdm_stuttgart/mi/sd1/figure/model/Circle.java
@@ -0,0 +1,29 @@
+package de.hdm_stuttgart.mi.sd1.figure.model;
+
+public class Circle extends Figure {
+
+   private double radius;
+   
+   public Circle(double x, double y, double radius) {
+      super(x, y);
+      setRadius(radius);
+   }
+   
+   /**
+    * @return The circle's area.
+    */
+   public double getArea() {
+     return radius * radius * Math.PI;
+   }
+
+   /**
+    * @return The circle's perimeter.
+    */
+   public double getPerimeter() {
+     return 2 * Math.PI * radius;
+   }
+
+   // Getter and setter methods for private attribute
+   public double getRadius() { return radius;}
+   public void setRadius(double radius) { this.radius = radius;}
+}
diff --git a/P/Sd1/Figure/BaseClass/src/main/java/de/hdm_stuttgart/mi/sd1/figure/model/Figure.java b/P/Sd1/Figure/BaseClass/src/main/java/de/hdm_stuttgart/mi/sd1/figure/model/Figure.java
new file mode 100644
index 000000000..bc02a53e3
--- /dev/null
+++ b/P/Sd1/Figure/BaseClass/src/main/java/de/hdm_stuttgart/mi/sd1/figure/model/Figure.java
@@ -0,0 +1,26 @@
+package de.hdm_stuttgart.mi.sd1.figure.model;
+
+public abstract class Figure {
+     
+   private double x,y;
+   
+   public Figure(double x, double y) {
+      setX(x);
+      setY(y);
+   }
+   
+   // To be implemented in derived classes Rectangle and Circle
+   public abstract double getArea();
+   public abstract double getPerimeter();
+   
+   public double getX() { return x;}
+   public void setX(double x) { this.x = x;}
+   public double getY() { return y;}
+   public void setY(double y) { this.y = y;}
+   
+   public final Figure move(double x, double y) {
+      setX(getX() + x);
+      setY(getY() + y);
+      return this;
+   }
+}
\ No newline at end of file
diff --git a/P/Sd1/Figure/BaseClass/src/main/java/de/hdm_stuttgart/mi/sd1/figure/model/Rectangle.java b/P/Sd1/Figure/BaseClass/src/main/java/de/hdm_stuttgart/mi/sd1/figure/model/Rectangle.java
new file mode 100644
index 000000000..ef0183dca
--- /dev/null
+++ b/P/Sd1/Figure/BaseClass/src/main/java/de/hdm_stuttgart/mi/sd1/figure/model/Rectangle.java
@@ -0,0 +1,38 @@
+package de.hdm_stuttgart.mi.sd1.figure.model;
+
+public class Rectangle extends Figure {
+
+// Instance variables representing a rectangle's additional parameters
+  private double width, height;
+   /**
+    *  
+    * @param width The rectangle's width
+    * @param heigth The rectangle's height
+    */
+   public Rectangle(double x, double y, int width, int height) {
+      super(x, y);
+      setWidth(width);
+      setHeight(height);
+   }
+   
+   /**
+    * @return The rectangle's area.
+    */
+   public double getArea() {
+     return width * height;
+   }
+
+   /**
+    * @return The rectangle's perimeter.
+    */
+   public double getPerimeter() {
+     return 2 * (width + height); 
+   }
+   
+   // Getter and setter methods for private attributes
+   public double getWidth() { return width;}
+   public void setWidth(double width) { this.width = width;}
+   public double getHeight() { return height;}
+   public void setHeight(double height) { this.height = height;}
+   
+}
\ No newline at end of file
diff --git a/P/pom.xml b/P/pom.xml
index d3194bc73..bd1cca0af 100644
--- a/P/pom.xml
+++ b/P/pom.xml
@@ -45,6 +45,8 @@
     <module>Sd1/fraction/V1</module>
     <module>Sd1/fraction/V2</module>
 
+    <module>Sd1/Figure/BaseClass</module>
+
     <module>Sd1/Gcd/V1</module>
 
     <module>Sd1/HtmlFormatting/Simple/Exercise</module>
-- 
GitLab