From cd6a9243c056710794549a1ab5d51fbdd082ce2e Mon Sep 17 00:00:00 2001 From: Sudipto Mallick Date: Sat, 27 Jan 2024 11:33:43 +0000 Subject: Complete Java assignments #7-13 --- java/text/ShapeAreaCalculations.typ | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 java/text/ShapeAreaCalculations.typ (limited to 'java/text/ShapeAreaCalculations.typ') diff --git a/java/text/ShapeAreaCalculations.typ b/java/text/ShapeAreaCalculations.typ new file mode 100644 index 0000000..f34c1a0 --- /dev/null +++ b/java/text/ShapeAreaCalculations.typ @@ -0,0 +1,27 @@ +#import "/template.typ": * +#show: A => apply(A) +#set raw(lang: "java-new") +#set par(leading: 0.6em) + +#assignment(13)[ + Write a program to create a class `Shape` with 4 methods to calculate the areas of triangle, rectangle, square, and circle using method overloading. +] + +#scos("ShapeAreaCalculations") + +=== Discussion + +#skind[Classes and methods implemented in the program] + +- The `Shape` class provides static methods for calculating the area of different geometric shapes: + - `static double area(double a, double b, double c)`: Calculates the area of a triangle using its side lengths. + - `static int area(int length, int width)`: Calculates the area of a rectangle using its length and width. + - `static int area(int sideLength)`: Calculates the area of a square using its side length. + - `static double area(double radius)`: Calculates the area of a circle using its radius. + +- The `ShapeAreaCalculations` class contains the main program for calculating the area of geometric shapes based on user input through a menu-driven interface: + - `static void menu()`: Displays a menu of shape choices. + - `public static void main(String[])`: Implements a menu-driven program for calculating the area of different shapes (_i.e._ triangle, rectangle, square, or circle) based on user input. + + +#signature() -- cgit 1.4.1-2-gfad0