For one of my classes I have to write basic Java code that will compute the area of a rectangle, triangle and circle. Here are the directions for the first:
The area of a rectangle is found by multiplying its ase and height. As such, define 3 integer variables in "main" : two for the base and height, and one for the area. Your program should read the base and height using the following format: Rectangle's base: 7 , Rectangle's height: 6 . . . and it should wrrite to the screen in the following format "the area of a rectangle of base 7 and height 6 is 42.
The next shape is a Triangle:
Continue extending your program by adding operations to calculate the area of a triangle.
The area of a triangle is found by multiplying its base and height and dividing this result by 2.
As such, define 3 additional variables in “main”: two integers for the base and height, and one double for the resulting area.
Your program should read the base and height using the following format
Triangle’s base: 21
Triangle’s height: 3
…and should write to the screen in the following format
The area of a triangle of base 21 and height 3 is 31.5
The next shape is a Circle:
The area of a circle is found by multiplying the square of its radius by π. For simplicity, assume that the value of π is 3.14159. The square of the radius is calculated by multiplying it by itself.
As such, define 2 additional double variables in “main”: one for the radius, and one for the area.
Your program should read the radius using the following format
Circle’s radius: 5
…and write to the screen in the following format
The area of a circle of radius 5.0 is 78.53975
Thanks, if you only have time to help with one that would still be greatly appreciated.
Dan