Question: Plesae solve in java Write an interactive program that computes the area of a square (area = side2) or triangle (area = 1/2 * base

Plesae solve in java

Write an interactive program that computes the area of a square (area = side2) or triangle (area = 1/2 * base * height) after prompting the user to type the first character of the figure name (t or s). Note that a square does not have a base and a height. It has only a side. Your variable names should reflect this.

Sample screen output 1:

Enter the type of figure (s or t): t Enter the base: 4 Enter the height: 3 The area is 6 Sample screen output 2:

Enter the type of figure (s or t): s Enter the length of a side: 9 The area is 81 You should read the user's input as a String using the input.next() method.

You may need to compare two Strings in order to complete this. You can't compare Strings using the == operator. You'll need to use the "equals()" method. It will look something like

if (string1.equals(string2))... Turn in your source code and 2 outputs, one reflecting each of the two sample screen outputs given above.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!