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

I need to make the following changes to the below code: In Ex2, you were asked t

ID: 1809569 • Letter: I

Question

I need to make the following changes to the below code: In Ex2, you were asked to add code to the method area() in the triangle class and test it in the main.*************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************** package lab1_2; import java.util.Scanner; public class Triangle { public static void main(String[] args) { Scanner input = new Scanner(System.in); double base = 0; double height = 0; double area = 0; System.out.print("Enter the length of base of triangle : "); base = input.nextDouble(); System.out.print("Enter the length of height of triangle : "); height = input.nextDouble(); area = (base * height) / 2; System.out.println(""); System.out.println("The Area of Triangle is : " + area); } }

Explanation / Answer

Below is the working code checked in eclipse

-------------------------------------------------


import java.util.Scanner;

public class Triangle

{

public static double area(double height,double base)

{

return (base * height) / 2 ;

}

public static void main(String[] args)

{

Scanner input = new Scanner(System.in);

double base = 0;

double height = 0;

double areaOfTriangle = 0;

System.out.print("Enter the length of base of triangle : ");

base = input.nextDouble();

System.out.print("Enter the length of height of triangle : ");

height = input.nextDouble();

areaOfTriangle = area(height,base);

System.out.println("The Area of Triangle is : " + areaOfTriangle);

}

}

----------------------

output

-----------------

Enter the length of base of triangle : 2

Enter the length of height of triangle : 3

The Area of Triangle is : 3.0