DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2006
    Posts
    29

    Question Triangle Property (class)

    I have a program that takes user input from a textbox. Based on those 3 numbers it will tell them whether it is a right triangle, equilateral triangle or not a triangle. I've written 3 properties (get/set) to take the lengths. Now I need two readonly (get only) properties s to determine whether something is right or equilateral. I'm really not sure how I would write the formula in vb. I understand a right triangle is a2 + b2 = c2 but i'm not sure how I could process a math formula inside a property. I guess I am also trying to learn how these two new properties would interact with the 3 already written? Here is what I have so far. I do not yet have anything for the right triangle. Does this make sense and anybody know how to easily calculate a right triangle. The formulas online haven't really made sense to me in order to write it out in vb.

    Code:
    Public Class Triangle
    
        'declare integers for 3 triangle sides
        Dim m_intSide1 As Integer
        Dim m_intSide2 As Integer
        Dim m_intSide3 As Integer
    
        'declare integers for triangle type
        Dim m_intRight As Integer
        Dim m_intEquilateral As Integer
    
        'Triangle constructor, sides supplied
        Public Sub New(ByVal side1Value As Integer, ByVal side2Value As Integer, _
            ByVal side3Value As Integer, ByVal RightTriangleValue As Integer, _
            ByVal EquilateralValue As Integer)
    
            m_intSide1 = side1Value
            m_intSide2 = side2Value
            m_intSide3 = side3Value
            m_intRight = RightTriangleValue
            m_intEquilateral = EquilateralValue
    
        End Sub 'New
    
        'property side1
        Public Property Side1() As Integer
    
            'return m_intSide1 value
            Get
                Return m_intSide1
            End Get 'end of Get accessor
    
            'set m_intside1 value
            Set(ByVal Value As Integer)
                'if side 1 value entered is valid
                If (Value > 0) Then
                    m_intSide1 = Value
                Else
                    m_intSide1 = 0  'set invalid input to 0
                End If
            End Set 'end of set accessor
        End Property
    
        'property side2
        Public Property Side2() As Integer
    
            'return m_intSide2 value
            Get
                Return m_intSide2
            End Get 'end of Get accessor
    
            'set m_intside2 value
            Set(ByVal Value As Integer)
                'if side 2 value entered is valid
                If (Value > 0) Then
                    m_intSide2 = Value
                Else
                    m_intSide2 = 0  'set invalid input to 0
                End If
            End Set 'end of set accessor
        End Property
    
        'property side3
        Public Property Side3() As Integer
    
            'return m_intSide3 value
            Get
                Return m_intSide3
            End Get 'end of Get accessor
    
            'set m_intside3 value
            Set(ByVal Value As Integer)
                'if side 3 value entered is valid
                If (Value > 0) Then
                    m_intSide3 = Value
                Else
                    m_intSide3 = 0  'set invalid input to 0
                End If
            End Set 'end of set accessor
        End Property
    
        'property IsRight (copied from below, work in progress)
        Public ReadOnly Property IsRight() As Integer
    
            'return m_intRightTriangle value
            Get
                If (Side1 = Side2 AndAlso Side2 = Side3) Then
                    Return m_intRight
                End If
    
            End Get 'end of Get accessor
    
        End Property
    
        'property IsEquilateral
        Public ReadOnly Property IsEquilateral() As Integer
    
            'return m_intEquilateral value
            Get
                If (Side1 = Side2 AndAlso Side2 = Side3) Then
                    Return m_intEquilateral
                End If
    
            End Get 'end of Get accessor
    
        End Property
    
    End Class   'Triangle

  2. #2
    Join Date
    Dec 2004
    Posts
    163
    geo039,

    I would consider making IsRight and IsEquilateral methods (public functions) that return boolean values.

    Kerry Moorman

  3. #3
    Join Date
    Nov 2006
    Posts
    29
    That's also how I approached it and since this is a hw assignment there are requirements and it has to be in a property but due to the timeframe I have normally at this point I just try to get it to work and take whatever credit I can get, so I may end up just putting it in a boolean function.

Similar Threads

  1. JDOM Classpath Help Required
    By kpandya in forum Java
    Replies: 5
    Last Post: 01-15-2006, 07:10 PM
  2. Events propagation
    By thegios in forum VB Classic
    Replies: 1
    Last Post: 09-19-2005, 02:08 PM
  3. How To Do It - Shared Class Variables Part IV
    By Patrick Ireland in forum .NET
    Replies: 3
    Last Post: 05-07-2001, 03:04 PM
  4. Replies: 0
    Last Post: 04-26-2001, 10:01 PM
  5. ActiveX Control Property Pages
    By Jerry Bumgarner in forum VB Classic
    Replies: 4
    Last Post: 07-14-2000, 10:48 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links