Given class Triangle (in file Triangle.java), complete main() to read and set the base and height of triangle1 and of tr

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Given class Triangle (in file Triangle.java), complete main() to read and set the base and height of triangle1 and of tr

Post by answerhappygod »

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()) }}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply