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