Question
Design and implement class Triangle that inherits form class GeometricObjects (provided to you with this assignment). Class Triangle has the following characteristics: Defines variables: side1,
Design and implement class Triangle that inherits form class GeometricObjects (provided to you with this assignment).
Class Triangle has the following characteristics:
Defines variables: side1, side2, and side3. Each is initialized with the value 1.0
Defines a default (non-argument) constructor to create a default triangle.
Defines a second constructor to allow the user to create triangles with user-specific side values.
Defines three access (get) methods, one for each variable, named getSide1(), getSide2(), and getSide3().
Defines method getArea() that computes and returns the area of a triangle object.
s = (side1 + side2 + side3)/2 Area = Sqrt(s(s-side1)(s-side2)(s-side3))
Defines method getPerimeter() that computes and returns the perimeter of a triangle object.
Perimeter = (side1 + side2 + side3)
Defines method toString() that returns a meaningful description of a triangle object including its name, sides, area, and perimeter in this format:
Triangle: myTriangle Side 1: 4 Side 2: 5 Side 3: 6
Area: 9.921567416492215 Perimeter: 15
Write a test program named testTriangle to create couple triangle object and test all of the class methods on those objects. Add proper labels to your outputs.
Step 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