Given class Triangle (in file Triangle.java), completemain() to read and set the base and height of triangle1 and oftriangle2, determine which triangle's area is smaller, and outputthat triangle's info, making use of Triangle's relevantmethods.
Ex: If the input is:
where 3.0 is triangle1's base, 4.0 is triangle1's height, 4.0 istriangle2's base, and 5.0 is triangle2's height, the output is:
import java.util.Scanner;
public class TriangleArea { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); Triangle triangle1 = new Triangle(); Triangle triangle2 = new Triangle();
// TODO: Read and set base and height fortriangle1 (use setBase() and setHeight()) // TODO: Read and set base and height fortriangle2 (use setBase() and setHeight()) System.out.println("Triangle with smallerarea:"); // TODO: Determine smaller triangle (usegetArea()) // and output smallertriangle's info (use printInfo()) }}
Given class Triangle (in file Triangle.java), complete main() to read and set the base and height of triangle1 and of tr
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am