
Java Program to Find the Area of a Triangle - GeeksforGeeks
Aug 5, 2024 · In this article, we will learn how to find the area of the triangle. There can be two possibilities while calculating the area of the triangle as per cases. Case 1: When the height and base of the triangle are given, then the area of the triangle is half the product of its base and height. Formula: Area of triangle: Area = (height×base)/2.
Java program to find area of rectangle triangle Interface
Write a Java program to define an interface called Area which contains a method called Compute () and calculate areas of the rectangle (I*b) and triangle (1/2*b*h) using classes Rectangle and Triangle.
Java - Abstract Shape Class with Circle and Triangle Subclasses
Feb 19, 2025 · Write a Java program to create an abstract class Shape with abstract methods calculateArea () and calculatePerimeter (). Create subclasses Circle and Triangle that extend the Shape class and implement the respective methods …
Java - Calculate the area and perimeter of shapes - w3resource
Feb 19, 2025 · The class provides implementations of the abstract methods "getArea ()" and "getPerimeter ()" to calculate the area and perimeter of the triangle based on its three sides using standard formulas.
java - Calculate area of square, triangle and circle using both ...
Mar 31, 2022 · A better way could be: make Shape abstract, and have an abstract method protected double computeArea() ... and a (non-abstract) method printArea () ... that calls the abstract one.
java - Creating an abstract class to get perimeter and area?
May 2, 2017 · The problem I was given: Write an abstract superclass encapsulating a shape: a shape has 2 abstract methods: one returning the perimeter of the shape, another returning the area of the shoe. It also has a constant field named PI. This class has two non-abstract subclasses: one encapsulating a circle, and the other encapsulating a rectangle.
Calculate the area of triangle and rectangle by using abstract class ...
Sep 25, 2018 · System.out.println ("Enter the Base or Width : "); float b = sc.nextFloat (); Area a = new Triangle (); a.cal (h,b); Area c = new Rectangle (); c.cal (h,b); a.display (); c.display (); } } …
java - area and perimeter calculation of various shapes - Stack Overflow
Dec 18, 2010 · Just look up the formulas for each one and write the single line of code that each requires. Sounds like somebody's classic first object-oriented assignment: double perimeter(); double area(); private double width; private double height; Rectangle(double w, double h) this.width = w; this.height = h; public double perimeter()
Java Program to find area of different shapes using inheritance
Mar 3, 2021 · This program demonstrates the use of interfaces and inheritance to calculate the area and perimeter of different shapes (Rectangle and Triangle). Interface AreaPerimeter: Defines two methods: calculateArea(float x, float y) to calculate the area of a shape. calculatePerimeter(float a, float b) to calculate the perimeter of a shape. Both methods are abstract (by default in an interface) and ...
Java: Abstract GeometricShape Class with Triangle and
Feb 19, 2025 · Write a Java program to create an abstract class GeometricShape with abstract methods area () and perimeter (). Create subclasses Triangle and Square that extend the GeometricShape class and implement the respective methods …
- Some results have been removed