Scenario: When I lived in Milton, Vermont, I owned a house out by the Sand Bar o
ID: 3842497 • Letter: S
Question
Scenario: When I lived in Milton, Vermont, I owned a house out by the Sand Bar off Rt. 2 that was situated on a triangular lot. According to the deed, this lot measured 300 feet of road frontage (side A or "base"), by 500 feet that bordered the Sand Bar Wildlife Preserve (side C or "hypotenuse") by 400 feet to the north (side B or "height"). Upon doing the math, it was determined that this lot was a right triangle and sat on approximately 1.4 acres.
Write a program that will: Ask the user to input Side A (base) and Side B (height) of a triangular lot Determine the acreage Inform the user (output) The length of Side C (hypotenuse) The total acreage Use Input and Output methods Required Input Side A and Side B
Hint: An acre of land = 43,560 sqft. This value cannot be changed A right triangle's area is defined as ½ the Base*Height The way to determine the hypotenuse of a right triangle (on the right) is defined by the Pythagorean Theorem, or A squared + B squared = C squared In Java, we can manipulate this formula and use the Math class API to determine the hypotenuse of a right triangle given the base and the height. With this in mind, consider the use of sqrt (square root) and pow (power) methods that are available within the Math class
Asq+ Bsq = C2sq
Explanation / Answer
//TriangleArea.java
import java.util.*;
import java.math.*;
import java.text.DecimalFormat;
public class TriangleArea {
public static void main(String args[]) {
double base, height, area, hypotenuse;
Scanner in = new Scanner(System.in);
System.out.println("Enter S1 (base) of the Triangle in feet: ");
base = in.nextDouble();
System.out.println("Enter S2 (height) of Triangle in feet: ");
height = in.nextDouble();
// Hypotenuse of the right angled triangle ;
hypotenuse= Math.sqrt(base*base+height*height);
// Hypotenuse can also be written as
//hypotenuse= Math.sqrt(Math.pow(base,2)+Math.pow(height,2));
area = (base * height)/2;
System.out.println("Hypotenuse Of the triangle: "+hypotenuse+" ft");
System.out.println("Area of Triangle = " + area+" sq.ft");
double areaInAcre =area/43560;//To convert sq.ft to Acre
DecimalFormat df = new DecimalFormat("##.##"); // To make sure it prints only two decimal points of the Area.
System.out.println("Area of Triangle = " + df.format(areaInAcre) +" Acres");
}
}
//End of class Triangle Area
Sample Output:
Enter S1 (base) of the Triangle in feet:
400
Enter S2 (height) of Triangle in feet:
300
Hypotenuse Of the triangle: 500.0 ft
Area of Triangle = 60000.0 sq.ft
Area of Triangle = 1.38 Acres
Ps: Please Rate it if You got the Answer..:) Thanks.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.