summary refs log tree commit diff stats
path: root/java/text/AbstractShapeCalculations.typ
blob: 83d3999dfd26cd492e7ef56a6ffad0d39db4f795 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#import "/template.typ": *
#show: A => apply(A)
#set raw(lang: "java-new")
#set par(leading: 0.6em)

#assignment(14, block: true)[
  Write a program to create an abstract class `Shape` with two abstract methods, `area()` and `display()` and make three concrete derived classes `Rectangle`, `Circle` and `Triangle` which can calculate area and display them seperately.
]

#scos("AbstractShapeCalculations")

=== Discussion

#skind[Classes and methods implemented in the program]

- The `Shape` abstract class:
  - `abstract double area()`: To be implemented by subclasses for calculating the area.
  - `abstract void display()`: To be implemented by subclasses for displaying shape details.

- The `Rectangle` class extends `Shape`:
  - `double area()`: Calculates the area of a rectangle using its length and width.
  - `void display()`: Displays details of the rectangle.

- The `Circle` class extends `Shape`:
  - `double area()`: Calculates the area of a circle using its radius.
  - `void display()`: Displays details of the circle.

- The `Triangle` class extends `Shape`:
  - `double area()`: Calculates the area of a triangle using its side lengths.
  - `double perimeter()`: Calculates the perimeter of a triangle.
  - `void display()`: Displays details of the triangle.

- The `AbstractShapeCalculations` class contains the main program:
  - `public static void main(String[])`: Implements a menu-driven program for calculating and displaying areas of different shapes (Rectangle, Circle, Triangle) based on user input. Utilizes abstract classes and polymorphism for handling various shapes and their respective calculations.

#signature()