1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
JulsSmile [24]
4 years ago
12

Triangle area comparison (classes) Given class Triangle, complete the program to read and set the base and height of triangle1 a

nd triangle2, determine which triangle's area is larger, and output the larger triangle's info, making use of Triangle's relevant methods. Ex: If the input is: 3.0 4.0 4.0 5.0 where 3.0 is triangle1's base, 4.0 is triangle1's height, 4.0 is triangle2's base, and 5.0 is triangle2's height, the output is: Triangle with larger area: Base: 4.00 Height: 5.00 Area: 10.00
Computers and Technology
1 answer:
Alenkinab [10]4 years ago
7 0

Answer:

// Triangle.java

public class Triangle {

   private double base;

   private double height;

   public void setBase(double base) {

       this.base = base;

   }

   public void setHeight(double height) {

       this.height = height;

   }

   public double getArea() {

       return 0.5 * base * height;

   }

 

   public void printInfo() {

       System.out.printf("Base: %.2f\n", base);

       System.out.printf("Height: %.2f\n", height);

       System.out.printf("Area: %.2f\n", getArea());

   }

}

// TriangleArea.java

import java.util.Scanner;

public class TriangleArea {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       double base1 = in.nextDouble();

       double height1 = in.nextDouble();

       double base2 = in.nextDouble();

       double height2 = in.nextDouble();

 

       Triangle triangle1 = new Triangle();

       triangle1.setBase(base1);

       triangle1.setHeight(height1);

       Triangle triangle2 = new Triangle();  

       triangle2.setBase(base2);

       triangle2.setHeight(height2);

       System.out.println("Triangle with larger area:");

       if (triangle1.getArea() > triangle2.getArea()) {

           triangle1.printInfo();

       } else {

           triangle2.printInfo();

       }

   }

}

Explanation:

  • Inside the getArea method, calculate the area by applying the following formula.

Area = 0.5 * base * height;

  • Get the input from user for both triangles.
  • Compare the area of both triangle and print the information of the larger triangle.
You might be interested in
10. Calculate the checksum for blocks of data with the following byte sum. (a) 1220 (b) 950​
OLga [1]

Answer:kalo gk salah yang

a

Explanation:

5 0
3 years ago
A chief Information Officer (CISO) is working with a consultant to perform a gap assessment prior to an upcoming audit. It is de
artcher [175]

Answer: (D) Vendor management plan

Explanation:

 The chief information officer (CISO) is basically explain about areas of the improvement to the vendors so that is why vendor management plan should be implemented to address the gap assessment in the upcoming audit.

Chief information officer basically managed all the report that are provided to the department of the audit on the monthly bases.

The vendor management are basically responsible for managing all the upcoming assessment in the audit in an organization.

8 0
3 years ago
What is required to create a game?
Y_Kistochka [10]

Answer: C. competition

Explanation:

6 0
2 years ago
30 POINTS!!!! HELPPPPP!!! in computer science, what does the term inference mean?
algol [13]

Answer:

a

Explanation:

the act or process of reaching a conclusion about something from known facts

4 0
2 years ago
Read 2 more answers
How does one copy and paste and cut on Windows OS?
pickupchik [31]

CTRL C TO COPY

CTRL V TO PASTE

CTRL X TO CUT

5 0
3 years ago
Read 2 more answers
Other questions:
  • When you need to cut new external threads on a bolt, what tool should you use?
    7·2 answers
  • What form of internet access currently uses a technology called 4gb?
    10·1 answer
  • A java program that calculates the balance of three months of $1000 and interest rate 6%
    9·1 answer
  • What date does GTA 6 come out<br> A. 2020<br> B. 2019<br> C. 2021<br> D. 2022
    10·2 answers
  • What is wrong with the formula below?<br><br> SUM(A1:A5)/SUM(B1:B5)
    7·1 answer
  • Ben is writing a paper for his college history class, and he wants to include some information he found on a Web site. What are
    5·1 answer
  • Choose one skill needed to become Computer Network Administrator?
    10·2 answers
  • The metric unit used for length
    5·1 answer
  • Ict quiz I attached a picture
    11·2 answers
  • You are investigating a problem between two wireless bridges and you find that signal strength is lower than expected. Which of
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!