diff options
Diffstat (limited to 'usth/ICT2.2/labwork/5/Java/abstract')
-rw-r--r-- | usth/ICT2.2/labwork/5/Java/abstract/Circle.java | 13 | ||||
-rw-r--r-- | usth/ICT2.2/labwork/5/Java/abstract/Cylinder.java | 14 | ||||
-rw-r--r-- | usth/ICT2.2/labwork/5/Java/abstract/Point.java | 13 | ||||
-rw-r--r-- | usth/ICT2.2/labwork/5/Java/abstract/Shape.java | 12 | ||||
-rw-r--r-- | usth/ICT2.2/labwork/5/Java/abstract/Test.java | 11 |
5 files changed, 63 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); + } +} |