From fc4d96a9e3e20f8ddf035c16fc32b1effb75481b Mon Sep 17 00:00:00 2001 From: Sudipto Mallick Date: Sun, 28 Jan 2024 06:38:55 +0000 Subject: Complete all Java assignments --- java/text/CircularBaseExample.typ | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 java/text/CircularBaseExample.typ (limited to 'java/text/CircularBaseExample.typ') diff --git a/java/text/CircularBaseExample.typ b/java/text/CircularBaseExample.typ new file mode 100644 index 0000000..2a9c495 --- /dev/null +++ b/java/text/CircularBaseExample.typ @@ -0,0 +1,37 @@ +#import "/template.typ": * +#show: A => apply(A) +#set raw(lang: "java-new") +#set par(leading: 0.7em) + +#assignment(18, block: true)[ + Write a program to create a class named `CircularBase` containing a method `getArea()` to calculate the base area, an interface named `_3dShape` with two methods `calArea()` and `calVolume()`, two subclasses of `CircularBase` named `Cone` and `Cylinder` implementing `_3dShape`; calculate the base area and volume of these shapes with the help of `calArea()` method. +] + +#scos("CircularBaseExample") + +=== Discussion + +#skind[Interfaces, classes and methods implemented in the program] + +- The `ThreeDimensionalShape` interface: + - `double calArea()`: Calculates the surface area of a three-dimensional shape. + - `double calVolume()`: Calculates the volume of a three-dimensional shape. + +- The `CircularBase` class: + - Constructor `CircularBase(double)`: Initializes a shape with a circular base using the provided radius. + - `double getArea()`: Calculates the area of the circular base. + +- The `Cone` class extends `CircularBase` and implements `ThreeDimensionalShape`: + - Constructor `Cone(double, double)`: Initializes a cone with a circular base, taking radius and height. + - `double calArea()`: Overrides the interface method to calculate the total surface area of the cone. + - `double calVolume()`: Overrides the interface method to calculate the volume of the cone. + +- The `Cylinder` class extends `CircularBase` and implements `ThreeDimensionalShape`: + - Constructor `Cylinder(double, double)`: Initializes a cylinder with a circular base, taking radius and height. + - `double calArea()`: Overrides the interface method to calculate the total surface area of the cylinder. + - `double calVolume()`: Overrides the interface method to calculate the volume of the cylinder. + +- The `CircularBaseExample` class contains the main program: + - `public static void main(String[])`: Takes user input for the dimensions of a cone and a cylinder, creates instances of these shapes, and displays their base area, total surface area, and volume. + +#signature() -- cgit 1.4.1-2-gfad0