Write 2 Java classes for a task to compute the area of a right triangle. The first Java class has the name RightTriangle in which you define a right triangle object with 2 fields representing the base and height of a right triangle and 1 method without arguments which computes and returns the area of a right triangle using the formula 0.5 x base x height. The first Java class has no main method. The second Java class has the name UsingRightTriangle and it has a main method in which you instantiate the first Java class to create an instance of it representing a right triangle. You get values for the base and height by user inputs and call its method to compute the area of the right triangle. Then, display as outputs the values of the base, height and area. Do the user inputs for base and height, area computation and display of outputs five times
Write 2 Java classes for a task to compute the area of a right triangle. The first Java class has the name RightTriangle in which you define a right triangle object with 2 fields representing the base and height of a right triangle and 1 method without arguments which computes and returns the area of a right triangle using the formula 0.5 x base x height. The first Java class has no main method. The second Java class has the name UsingRightTriangle and it has a main method in which you instantiate the first Java class to create an instance of it representing a right triangle. You get values for the base and height by user inputs and call its method to compute the area of the right triangle. Then, display as outputs the values of the base, height and area. Do the user inputs for base and height, area computation and display of outputs five times.
Step by step
Solved in 3 steps with 1 images