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...

  • 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...

  • Objective Extend the class GeometicShapes to include a Triangle class.. Background Reading ZyBooks Chapter 10 Task...

    Objective Extend the class GeometicShapes to include a Triangle class.. Background Reading ZyBooks Chapter 10 Task Create the following fields and methods for a Triangle class that extends the provided GeometricShapes class public class GeometricShapes { private String color = "red"; private boolean filled; private java.util.Date dateCreated;    public GeometricShapes() { dateCreated = new java.util.Date(); }    public GeometricShapes(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; }    public void setColor (String color)...

  • 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...

  • Design a general class GeometricObject can be used to model all geometric objects. This class contains...

    Design a general class GeometricObject can be used to model all geometric objects. This class contains the properties color and filled and their appropriate get and set methods. Assume that this class also contains toString() methods. The toString() method returns a string representation of the object. Define the Triangle, Circle, and Rectangle classes that extend the GeometricObject class. The Triangle class inherits all accessible data fields and methods from the GeometricObject class.In addition, it has three double data fields named...

  • 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...

  • In Java, write a class for a Triangle Object that contains, Private instance variables: - three...

    In Java, write a class for a Triangle Object that contains, Private instance variables: - three doubles: a,b,c, representing the three sides of the Triangle - constructor with three double as args, which are put into three instances variables Public Instance Methods: - getPerimeter: computes the perimeter of the triangle(the sum of the three sides), returns a double - getArea: computes the area of the triangle using Heron's formula: Area = (s*(s-a)*(s-b)*(s-c))^0.5, where s = 0.5*(the triangle's perimeter), returns a...

  • 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 -...

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