JAVA PLEASE Starting with your solution to the previous task, add the following methods to your ScaleneTriangle class to extend its functionality. A default (or "no-argument" or "no-arg") constructor that constructs a Triangle object using default values. An overloaded constructor that constructs a Triangle object with the given values. A method named getArea() which returns the area of a triangle. This method returns a double. The are is calculated by: √(s * (s - sideA) * (s - sideB) * (s - sideC)) where s = (sideA + sideB + sideC) / 2 Write the ScaleneTriangle class in the answer box below assuming that the superclass is given. For example:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

JAVA PLEASE

Starting with your solution to the previous task, add the following methods to your ScaleneTriangle class to extend its functionality.

  • A default (or "no-argument" or "no-arg") constructor that constructs a Triangle object using default values.
  • An overloaded constructor that constructs a Triangle object with the given values.
  • A method named getArea() which returns the area of a triangle. This method returns a double. The are is calculated by: √(s * (s - sideA) * (s - sideB) * (s - sideC)) where s = (sideA + sideB + sideC) / 2

Write the ScaleneTriangle class in the answer box below assuming that the superclass is given.

For example:



   
   
   

abstract class Triangle {

protected double sideA;

protected double sideB;

protected double sideC;

public Triangle() {

sideA = sideB = sideC = 10;

}

public Triangle(double sideA, double sideB, double sideC) {

this.sideA = sideA;

this.sideB = sideB;

this.sideC = sideC;

}

public double getSideA() {

return sideA;

}

public double getSideB() {

return sideB;

}

public double getSideC() {

return sideC;

}

public abstract double getArea();

public double getPerimeter() {

return sideA + sideB + sideC;

}

 

public String toString() {

return

String.format("%s:(%.2f, %.2f, %.2f)",

getClass().getName(), sideA, sideB, sideC);

}

}

 

Test
ScaleneTriangle t1 = new ScaleneTriangle();
System.out.printf("%s, perimeter=%.2f,
area= %.2f\n", t1.toString(), t1.getPerimeter (),
t1.getArea());
System.out.println(t1 instanceof Triangle);
ScaleneTriangle t1 = new ScaleneTriangle(2.0,
3.0, 4.0);
ScaleneTriangle t2 = new ScaleneTriangle();
System.out.printf("%s, perimeter=%.2f,
area= %.2f\n", t1.toString(), t1.getPerimeter (),
t1.getArea());
System.out.printf("%s, perimeter=%.2f,
area= %.2f\n", t2.toString(), t2.getPerimeter(),
t2.getArea());
Result
ScaleneTriangle: (10.00, 10.00,
10.00), perimeter=30.00,
area=43.30
true
Scalene Triangle: (2.00, 3.00,
4.00), perimeter=9.00,
area=2.90
Scalene Triangle: (10.00, 10.00,
10.00), perimeter=30.00,
area=43.30
Transcribed Image Text:Test ScaleneTriangle t1 = new ScaleneTriangle(); System.out.printf("%s, perimeter=%.2f, area= %.2f\n", t1.toString(), t1.getPerimeter (), t1.getArea()); System.out.println(t1 instanceof Triangle); ScaleneTriangle t1 = new ScaleneTriangle(2.0, 3.0, 4.0); ScaleneTriangle t2 = new ScaleneTriangle(); System.out.printf("%s, perimeter=%.2f, area= %.2f\n", t1.toString(), t1.getPerimeter (), t1.getArea()); System.out.printf("%s, perimeter=%.2f, area= %.2f\n", t2.toString(), t2.getPerimeter(), t2.getArea()); Result ScaleneTriangle: (10.00, 10.00, 10.00), perimeter=30.00, area=43.30 true Scalene Triangle: (2.00, 3.00, 4.00), perimeter=9.00, area=2.90 Scalene Triangle: (10.00, 10.00, 10.00), perimeter=30.00, area=43.30
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education