Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a java program that calculates of rectangular and right triangles Your mai

ID: 3798272 • Letter: W

Question

Write a java program that calculates of rectangular and right triangles Your main function should able to call two functions: calculateTriangle and calculateRectangle Each function is passed two parameters: length and width for the rectangle and side A and side B for the right triangle. The functions should return the area of the shape they calculated. The main function then only outputs the areas of the two calculated areas The rectangle has an area and right triangle has an area Write a java program that calculates of rectangular and right triangles Your main function should able to call two functions: calculateTriangle and calculateRectangle Each function is passed two parameters: length and width for the rectangle and side A and side B for the right triangle. The functions should return the area of the shape they calculated. The main function then only outputs the areas of the two calculated areas The rectangle has an area and right triangle has an area Your main function should able to call two functions: calculateTriangle and calculateRectangle Each function is passed two parameters: length and width for the rectangle and side A and side B for the right triangle. The functions should return the area of the shape they calculated. The main function then only outputs the areas of the two calculated areas The rectangle has an area and right triangle has an area

Explanation / Answer

class ShapeArea
{
  
void area(float x, float y) //method which calculates area of rectangle
{
System.out.println("the area of the rectangle is "+x*y+" sq units");
}
void area(double x,double y) // method which calculates area of right triangle
{
double z = 0.5 * x * y;
System.out.println("the area of the circle is "+z+" sq units");
}
}
class Sample
{
public static void main(String args[])
   {
   ShapeArea sa = new ShapeArea(); // created object of shapearea class
  
   sa.area(6,3); // calling area of rectangle with the shapearea object
   sa.area(2,5); // calling area of triangle with the shapearea object
}
}

sample output:

the area of the rectangle is 18 sq units
the area of the trianglr is 2 sq units

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote