Answered step by step
Verified Expert Solution
Question
1 Approved Answer
the code should be in java. please use variables for scanner input and also show me the results of the sample inputs. Implement the following
the code should be in java. please use variables for scanner input and also show me the results of the sample inputs.
Implement the following classes: Polygon numSide: int /* constructor */ /* accessor-mutator */ + area (): double + perimeter(): double Triangle sideA: double sideB: double sidec: double * constructor */ /* accessor-mutator */ + area(): double + perimeter(): double Create an object for Triangle class and invoke area and perimeter method. Input Format Take triangle sides (sideA, sideB, sideC) as input from user. Constraints For Triangle, sideB+side > sideA Heron's Formula Area of a Triangle from Sides You can calculate the area of a triangle if you know the lengths of all three sides, using a formula that has been known for nearly 2000 years. It is called "Heron's Formula" after Hero of Alexandria (see below) Just use this two step process: Step 1: Calculate "s" (half of the trangles perimeter): a+b+c S = c Step 2: Then calculate the Area: A=/s(s-a) (s - b) ( sc) Output Format Print Triangle area and perimeter as shown in sample output. Sample Input o 24 30 18 Sample Output o 216.00 72.00 Explanation 0 Here, sideA = 24.00 sideB 30.00 sideC - 18.00 Triangle Area - 216.08 Triangle Perimeter = 72.00 Sample Input 1 54 105 45 Sample Output 1 INVALID Explanation 1 The Triangle inequality Theorem states that the sum of any 2 sides of a triangle must be greater than the measure of the third side. Note: This rule must be satisfied for all 3 conditions of the sidesStep 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