Imports System.Collections
public class Test
public Shared Sub Main
Dim objShape1 As New Triangle
Dim objShape2 As New Circle
Dim objShape3 As New Square
Dim ShapeEnum As IEnumerator
Dim dblTotalArea As Double
objShape1.SideA = 3
objShape1.SideB = 3.2
objShape1.SideC = 0.94
Console.WriteLine("The triangle's area is " & objShape1.Area.ToString & ".")
objShape2.Radius = 4
Console.WriteLine("The circle's area is " & objShape2.Area.ToString & ".")
objShape3.Side = 10.01
Console.WriteLine("The square's area is " & objShape3.Area.ToString & ".")
Dim aryShapes() As Shape = {objShape1, objShape2, objShape3}
ShapeEnum = aryShapes.GetEnumerator
While ShapeEnum.MoveNext
dblTotalArea += CType(ShapeEnum.Current, Shape).Area
End While
Console.WriteLine("The total area of your shapes is " & dblTotalArea.ToString & ".")
End Sub
End class
Public MustInherit Class Shape
Public MustOverride Function Area() As Double
Public MustOverride Function Perimeter() As Double
End Class
Public Class Square
Inherits Shape
Private mySide As Double
Public Property Side() As Double
Get
Side = mySide
End Get
Set(ByVal Value As Double)
mySide = Value
End Set
End Property
Public Overrides Function Area() As Double
Area = mySide * mySide
End Function
Public Overrides Function Perimeter() As Double
Return (4 * mySide)
End Function
End Class
Public Class Triangle
Inherits Shape
Private mySide1, mySide2, mySide3 As Double
Property SideA() As Double
Get
SideA = mySide1
End Get
Set(ByVal Value As Double)
mySide1 = Value
End Set
End Property
Property SideB() As Double
Get
SideB = mySide2
End Get
Set(ByVal Value As Double)
mySide2 = Value
End Set
End Property
Public Property SideC() As Double
Get
SideC = mySide3
End Get
Set(ByVal Value As Double)
mySide3 = Value
End Set
End Property
Public Overrides Function Area() As Double
Dim dblPerim As Double
dblPerim = Perimeter()
Return (Math.Sqrt(dblPerim * (dblPerim - mySide1) * _
(dblPerim - mySide2) * (dblPerim - mySide3)))
End Function
Public Overrides Function Perimeter() As Double
Return (mySide1 + mySide2 + mySide3)
End Function
Sub New(ByVal SideA As Double, ByVal SideB As Double, ByVal SideC As Double)
MyBase.New()
mySide1 = SideA
mySide2 = SideB
mySide3 = SideC
End Sub
Sub New()
MyBase.New()
End Sub
End Class
Public Class Circle
Inherits Shape
Private m_dblRadius As Double
Public Property Radius() As Double
Get
Radius = m_dblRadius
End Get
Set(ByVal Value As Double)
m_dblRadius = Value
End Set
End Property
Public Overrides Function Area() As Double
Return (Math.PI * m_dblRadius ^ 2)
End Function
Public Overrides Function Perimeter() As Double
Return (2 * Math.PI * m_dblRadius)
End Function
Sub New()
MyBase.New()
End Sub
Sub New(ByVal Radius As Double)
MyBase.New()
m_dblRadius = Radius
End Sub
End Class
The triangle's area is 26.8715818068085.
The circle's area is 50.2654824574367.
The square's area is 100.2001.
The total area of your shapes is 177.337164264245.