Question
java .not c++ Write an interactive program that computes the area of a square (area = side 2 ) or triangle (area = 1/2 *
java .not c++
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started