Question

Equilateral Triangle Class EqTri Write a class that has several functions related to an Equilateral length : float Triangle. The constructor shouldgetArea): float accept a one parameter for the +getPerimeter): float length (which is the same for all 3+float-0 : float sides in an equilateral triangle) + _str) string -str--() method should return a string such as Rectangle (Area:50) float) method should return the area (Same functionality as getArea) Math (area- length?, perim/circum 3 length)

Using python 3.x to solve this problem.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
class EqTri:
    def __init__(self, length=0.0):
        self.length = length

    def getArea(self):
        return (3**0.5 / 4) * self.length ** 2

    def getPerimeter(self):
        return 3 * self.length

    def __str__(self):
        return 'EqTri (Area:' + str(self.getArea()) + ')'

    def __float__(self):
        return float(self.getArea())


t = EqTri(5)
print('Area = ' + str(t.getArea()))
print('Perimeter = ' + str(t.getPerimeter()))
print(t)
print(float(t))

Area 10.825317547305483 Perimeter 15 EqTri (Area: 10.825317547305483) 10.825317547305483 Process finished with exit code

Add a comment
Know the answer?
Add Answer to:
Using python 3.x to solve this problem. Equilateral Triangle Class EqTri Write a class that has...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (The Triangle class) Design a class named Triangle that extends the GeometricObject class. The Triangle class...

    (The Triangle class) Design a class named Triangle that extends the GeometricObject class. The Triangle class contains: - Three float data fields named side1, side2, and side3 to denote the three sides of the triangle. - A constructor that creates a triangle with the specified side1, side2, and side3 with default values 1.0. - The accessor methods for all three data fields. - A method named getArea() that returns the area of this triangle. - A method named getPerimeter() that...

  • Python only please, thanks in advance. Type up the GeometricObject class (code given on the back...

    Python only please, thanks in advance. Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...

  • Type up the GeometricObject class (code given on the back of the paper). Name this file Geometric...

    Python only please, thanks in advance. Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...

  • C++ The Shape.hcontains the information of the length of an edge. The derived triangle class has...

    C++ The Shape.hcontains the information of the length of an edge. The derived triangle class has the length of the height of the corresponding edge. Use the two values to compute the area of this triangle in getarea member function.Create the instance and output its result in the main function. Triangle.cpp: #include "triangle.h" Triangle ::Triangle() { //default constructor } float Triangle ::getarea() { //compute the area of the shape } void Triangle ::setheight( float h ) { //set the height...

  • Introduction to Java:Design a class named Triangle that extends GeometricObject.

    Please include comments in the program .The program must be able to be compiled.Design a class named Triangle that extends GeometricObject. This class contains:* Three double data fields named side1, side2, and side3 with default values 1.0 to denote the three sides of a triangle.* A no-arg constructor that creates a default triangle.* A constructor that creates a triangle with the specified side1, side2, and side3.* The accessor methods for all three data fields.* A method named getArea() that returns...

  • NEEDS TO BE IN PYTHON: (The Rectangle class) Following the example of the Circle class in...

    NEEDS TO BE IN PYTHON: (The Rectangle class) Following the example of the Circle class in Section 9.2, design a class named Rectangle to represent a rectangle. The class contains: - Two data fields named width and height. - A constructor that creates a rectangle with the specified width and height. The default values are 1 and 2 for the width and height, respectively. - A method named getArea() that returns the area of this rectangle. - A method named...

  • Must be in Python 3.6 (please have a screen shot on the code) ex 2.14 :...

    Must be in Python 3.6 (please have a screen shot on the code) ex 2.14 : # Enter three points for a triangle x1, y1, x2, y2, x3, y3 = eval(input("Enter three points for a triangle: ")) # Compute the length of the three sides side1 = ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) ** 0.5 side2 = ((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 -...

  • Within NetBeans, write a Java program for EACH of the following problems. (The Rectangle class) Following...

    Within NetBeans, write a Java program for EACH of the following problems. (The Rectangle class) Following the example of the Circle class in Section 9.2, design a class named Rectangle to represent a rectangle. The class contains: · Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. · A no-arg constructor that creates a default rectangle. · A constructor that creates a...

  • java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectang...

    java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...

  • JAVA design a class named Rectangle to represent a rectangle. The class contains: A method named getPerimeter() that returns the perimeter. Two double data fields named width and height that specify...

    JAVA design a class named Rectangle to represent a rectangle. The class contains: A method named getPerimeter() that returns the perimeter. Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. A no-arg constructor that creates a default rectangle. A constructor that creates a rectangle with the specified width and height. A method named getArea() that returns the area of this rectangle. design...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT