about summary refs log tree commit diff
path: root/usth/ICT2.2/labwork/5/Java
diff options
context:
space:
mode:
Diffstat (limited to 'usth/ICT2.2/labwork/5/Java')
-rw-r--r--usth/ICT2.2/labwork/5/Java/abstract/Circle.java13
-rw-r--r--usth/ICT2.2/labwork/5/Java/abstract/Cylinder.java14
-rw-r--r--usth/ICT2.2/labwork/5/Java/abstract/Point.java13
-rw-r--r--usth/ICT2.2/labwork/5/Java/abstract/Shape.java12
-rw-r--r--usth/ICT2.2/labwork/5/Java/abstract/Test.java11
-rw-r--r--usth/ICT2.2/labwork/5/Java/interface/Circle.java13
-rw-r--r--usth/ICT2.2/labwork/5/Java/interface/Cylinder.java14
-rw-r--r--usth/ICT2.2/labwork/5/Java/interface/Point.java21
-rw-r--r--usth/ICT2.2/labwork/5/Java/interface/Shape.java6
-rw-r--r--usth/ICT2.2/labwork/5/Java/interface/Test.java11
10 files changed, 128 insertions, 0 deletions
diff --git a/usth/ICT2.2/labwork/5/Java/abstract/Circle.java b/usth/ICT2.2/labwork/5/Java/abstract/Circle.java
new file mode 100644
index 0000000..3ee8c84
--- /dev/null
+++ b/usth/ICT2.2/labwork/5/Java/abstract/Circle.java
@@ -0,0 +1,13 @@
+public class Circle extends Point
+{
+  public double r;
+
+  public Circle(double x, double y, double r)
+  {
+    super(x, y);
+    this.r = r;
+  }
+
+  public double calArea() { return r * r * Math.PI; }
+  public String getName() { return "Circle"; }
+}
diff --git a/usth/ICT2.2/labwork/5/Java/abstract/Cylinder.java b/usth/ICT2.2/labwork/5/Java/abstract/Cylinder.java
new file mode 100644
index 0000000..8fa9e0c
--- /dev/null
+++ b/usth/ICT2.2/labwork/5/Java/abstract/Cylinder.java
@@ -0,0 +1,14 @@
+public class Cylinder extends Circle
+{
+  public double h;
+
+  public Cylinder(double x, double y, double r, double h)
+  {
+    super(x, y, r);
+    this.h = h;
+  }
+
+  public double calArea() { return super.calArea()*2.0 + r*h*Math.PI*2.0; }
+  public double calVolume() { return super.calArea() * h; }
+  public String getName() { return "Circle"; }
+}
diff --git a/usth/ICT2.2/labwork/5/Java/abstract/Point.java b/usth/ICT2.2/labwork/5/Java/abstract/Point.java
new file mode 100644
index 0000000..f6daf22
--- /dev/null
+++ b/usth/ICT2.2/labwork/5/Java/abstract/Point.java
@@ -0,0 +1,13 @@
+public class Point extends Shape
+{
+  public double x;
+  public double y;
+
+  public Point(double x, double y)
+  {
+    this.x = x;
+    this.y = y;
+  }
+
+  public String getName() { return "Point"; }
+}
diff --git a/usth/ICT2.2/labwork/5/Java/abstract/Shape.java b/usth/ICT2.2/labwork/5/Java/abstract/Shape.java
new file mode 100644
index 0000000..dd4124c
--- /dev/null
+++ b/usth/ICT2.2/labwork/5/Java/abstract/Shape.java
@@ -0,0 +1,12 @@
+public abstract class Shape
+{
+  public double calArea() { return 0.0; }
+  public double calVolume() { return 0.0; }
+  public abstract String getName();
+
+  public String toString()
+  {
+    return String.format("%s of area %g and volume %g",
+                         getName(), calArea(), calVolume());
+  }
+}
diff --git a/usth/ICT2.2/labwork/5/Java/abstract/Test.java b/usth/ICT2.2/labwork/5/Java/abstract/Test.java
new file mode 100644
index 0000000..b0502f0
--- /dev/null
+++ b/usth/ICT2.2/labwork/5/Java/abstract/Test.java
@@ -0,0 +1,11 @@
+import static java.util.Arrays.asList;
+
+class Test
+{
+  public static void main(String... args)
+  {
+    var array = asList(new Point(1.0, 2.0), new Circle(3.0, 4.0, 5.0),
+                       new Cylinder(6.0, 7.0, 8.0, 9.0));
+    array.forEach(System.out::println);
+  }
+}
diff --git a/usth/ICT2.2/labwork/5/Java/interface/Circle.java b/usth/ICT2.2/labwork/5/Java/interface/Circle.java
new file mode 100644
index 0000000..3ee8c84
--- /dev/null
+++ b/usth/ICT2.2/labwork/5/Java/interface/Circle.java
@@ -0,0 +1,13 @@
+public class Circle extends Point
+{
+  public double r;
+
+  public Circle(double x, double y, double r)
+  {
+    super(x, y);
+    this.r = r;
+  }
+
+  public double calArea() { return r * r * Math.PI; }
+  public String getName() { return "Circle"; }
+}
diff --git a/usth/ICT2.2/labwork/5/Java/interface/Cylinder.java b/usth/ICT2.2/labwork/5/Java/interface/Cylinder.java
new file mode 100644
index 0000000..8fa9e0c
--- /dev/null
+++ b/usth/ICT2.2/labwork/5/Java/interface/Cylinder.java
@@ -0,0 +1,14 @@
+public class Cylinder extends Circle
+{
+  public double h;
+
+  public Cylinder(double x, double y, double r, double h)
+  {
+    super(x, y, r);
+    this.h = h;
+  }
+
+  public double calArea() { return super.calArea()*2.0 + r*h*Math.PI*2.0; }
+  public double calVolume() { return super.calArea() * h; }
+  public String getName() { return "Circle"; }
+}
diff --git a/usth/ICT2.2/labwork/5/Java/interface/Point.java b/usth/ICT2.2/labwork/5/Java/interface/Point.java
new file mode 100644
index 0000000..90b2569
--- /dev/null
+++ b/usth/ICT2.2/labwork/5/Java/interface/Point.java
@@ -0,0 +1,21 @@
+public class Point implements Shape
+{
+  public double x;
+  public double y;
+
+  public Point(double x, double y)
+  {
+    this.x = x;
+    this.y = y;
+  }
+
+  public double calArea() { return 0.0; }
+  public double calVolume() { return 0.0; }
+  public String getName() { return "Point"; }
+
+  public String toString()
+  {
+    return String.format("%s of area %g and volume %g",
+                         getName(), calArea(), calVolume());
+  }
+}
diff --git a/usth/ICT2.2/labwork/5/Java/interface/Shape.java b/usth/ICT2.2/labwork/5/Java/interface/Shape.java
new file mode 100644
index 0000000..1eb33fa
--- /dev/null
+++ b/usth/ICT2.2/labwork/5/Java/interface/Shape.java
@@ -0,0 +1,6 @@
+interface Shape
+{
+  public double calArea();
+  public double calVolume();
+  public String getName();
+}
diff --git a/usth/ICT2.2/labwork/5/Java/interface/Test.java b/usth/ICT2.2/labwork/5/Java/interface/Test.java
new file mode 100644
index 0000000..b0502f0
--- /dev/null
+++ b/usth/ICT2.2/labwork/5/Java/interface/Test.java
@@ -0,0 +1,11 @@
+import static java.util.Arrays.asList;
+
+class Test
+{
+  public static void main(String... args)
+  {
+    var array = asList(new Point(1.0, 2.0), new Circle(3.0, 4.0, 5.0),
+                       new Cylinder(6.0, 7.0, 8.0, 9.0));
+    array.forEach(System.out::println);
+  }
+}