Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have the code for the Area completed. I just need help inputing the volume cod

ID: 3691871 • Letter: I

Question

I have the code for the Area completed. I just need help inputing the volume code into my prewritten code I posed bellow. I will also post my private subs for each written sub name. my windows form is also attched bellow.

create a interactive Windows form program to calculate the area and volume of some spherical shapes, specifically a circle, sphere, and cylinder.

1. The two inputs are the radius and the height.

2.If the height is zero you are to calculate the area and volume of a circle and a sphere.

3.If the height is greater than zero than you are to calculate only the area and volume of a cylinder.

You should create three classes: one for sphere, one for circle and one for cylinder. Methods and attributes unique to the geometric shapes should be part of that respective class.

Additionally, the radius should be constrained between 0 and 50 and the height should be constrained between 0 and 100.

Im using visual studio 2015. Code Language is: Visual Basic

1. Private Sub txtCricleVolume_TextChanged(sender As Object, e As EventArgs) Handles txtCricleVolume.TextChanged

    End Sub

2. Private Sub txtSphereVolume_TextChanged(sender As Object, e As EventArgs) Handles txtSphereVolume.TextChanged

    End Sub

3.   Private Sub txtCylinderVolume_TextChanged(sender As Object, e As EventArgs) Handles txtCylinderVolume.TextChanged

    End Sub

---------------------------------Windows form1 code--------------------------------


Public Class Form1
    Const PI As Double = 3.1419

    Public Class Circle
        Private m_radius As Double

        Public Property Radius() As Double
            Get
                Return m_radius
            End Get
            Set(value As Double)

                If Not (value >= 1 And value <= 50) Then

                    MsgBox("Please enter the radius within range (1-50)")

                Else
                    m_radius = value
                End If

            End Set
        End Property

        Public Function GetArea() As Double
            Return PI * m_radius * m_radius
        End Function
    End Class

    Public Class Sphere
        Private m_radius As Double
        Public Property Radius() As Double
            Get
                Return m_radius
            End Get
            Set(value As Double)
                If Not (value >= 1 And value <= 50) Then
                    MsgBox("Please enter the radius within range (1-50)")
                Else
                    m_radius = value
                End If

            End Set
        End Property
        Public Function GetArea() As Double
            Return 4 * PI * m_radius * m_radius
        End Function
    End Class

    Public Class Cylinder
        Private m_radius As Double
        Private m_height As Double
        Public Property Radius() As Double
            Get
                Return m_radius
            End Get
            Set(Value As Double)
                If Not (Value >= 1 And Value <= 50) Then
                    MsgBox("Please enter the radius within range (1-50)")

                Else
                    m_radius = Value
                End If
            End Set
        End Property

        Public Property Height() As Double

            Get
                Return m_height
            End Get
            Set(Value As Double)
                If Not (Value >= 0 And Value <= 100) Then
                    MsgBox("Please enter the height within range (0-100)")

                Else
                    m_height = Value
                End If
            End Set

        End Property
        Public Function GetArea() As Double
            Return (2 * PI * m_radius * m_height) + (2 * PI * m_radius * m_radius)
        End Function
    End Class

    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
        Dim o1 As Circle = New Circle()
        Dim o2 As Sphere = New Sphere()
        Dim cylinder1 As Cylinder = New Cylinder()
        Dim cylinder2 As Cylinder = New Cylinder()

        o1.Radius = Convert.ToDouble(txtInputRadius.Text)
        o2.Radius = Convert.ToDouble(txtInputRadius.Text)
        cylinder1.Radius = Convert.ToDouble(txtInputRadius.Text)
        cylinder2.Height = Convert.ToDouble(txtInputHeight.Text)

        If Convert.ToDouble(txtInputHeight.Text) = 0 Then
            txtCircleArea.Text = o1.GetArea().ToString()
            txtSphereArea.Text = o2.GetArea().ToString()
            txtCylinderArea.Text = "Not Applicable"
        Else
            txtCircleArea.Text = "Not Applicable"
            txtSphereArea.Text = "Not Applicable"
            txtCylinderArea.Text = cylinder1.GetArea().ToString()
        End If

    End Sub

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        txtInputRadius.Clear()
        txtInputHeight.Clear()
        txtCircleArea.Clear()
        txtSphereArea.Clear()
        txtCylinderArea.Clear()
    End Sub


End Class

Explanation / Answer

I think, there is some mistake in the question regarding calculating volume of the circle. I did not come across calculating voulme of a circle in my maths class. ;)

However, I think we can calculate the circumference of a circle.

Following are the required subs for calculating circumference of the circle, and volume of sphere and cylinder.

---------------------------------Windows form1 code--------------------------------


Public Class Form1
    Const PI As Double = 3.1419

    Public Class Circle
        Private m_radius As Double

        Public Property Radius() As Double
            Get
                Return m_radius
            End Get
            Set(value As Double)
                If Not (value >= 1 And value <= 50) Then
                    MsgBox("Please enter the radius within range (1-50)")
                Else
                    m_radius = value
                End If
            End Set
        End Property

        Public Function GetArea() As Double
            Return PI * m_radius * m_radius
        End Function
  
        Public Function GetCircumference() As Double
            Return 2 * PI * m_radius
        End Function

    End Class

    Public Class Sphere
        Private m_radius As Double

        Public Property Radius() As Double
            Get
                Return m_radius
            End Get
            Set(value As Double)
                If Not (value >= 1 And value <= 50) Then
                    MsgBox("Please enter the radius within range (1-50)")
                Else
                    m_radius = value
                End If
            End Set
        End Property

        Public Function GetArea() As Double
            Return 4 * PI * m_radius * m_radius
        End Function

        Public Function GetVolume() As Double
            Return 1.33 * PI * m_radius * m_radius * m_radius
        End Function

    End Class

    Public Class Cylinder
        Private m_radius As Double
        Private m_height As Double

        Public Property Radius() As Double
            Get
                Return m_radius
            End Get
            Set(Value As Double)
                If Not (Value >= 1 And Value <= 50) Then
                    MsgBox("Please enter the radius within range (1-50)")
                Else
                    m_radius = Value
                End If
            End Set
        End Property

        Public Property Height() As Double
            Get
                Return m_height
            End Get
            Set(Value As Double)
                If Not (Value >= 0 And Value <= 100) Then
                    MsgBox("Please enter the height within range (0-100)")
                Else
                    m_height = Value
                End If
            End Set
        End Property

        Public Function GetArea() As Double
            Return (2 * PI * m_radius * m_height) + (2 * PI * m_radius * m_radius)
        End Function

        Public Function GetVolume() As Double
            Return PI * m_radius * m_radius * m_height
        End Function

    End Class

    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
        Dim o1 As Circle = New Circle()
        Dim o2 As Sphere = New Sphere()
        Dim cylinder1 As Cylinder = New Cylinder()

        o1.Radius = Convert.ToDouble(txtInputRadius.Text)
        o2.Radius = Convert.ToDouble(txtInputRadius.Text)
        cylinder1.Radius = Convert.ToDouble(txtInputRadius.Text)

         'You don't need another cylinder object. Height must be assigned to cylinder1 only.
        cylinder1.Height = Convert.ToDouble(txtInputHeight.Text)

        If Convert.ToDouble(txtInputHeight.Text) = 0 Then
            txtCircleArea.Text = o1.GetArea().ToString()
            txtCircleVolume.Text = o2.GetCircumference().ToString()
            txtSphereArea.Text = o2.GetArea().ToString()
        txtSphereVolume.Text = o2.GetVolume().ToString()
            txtCylinderArea.Text = "Not Applicable"
        txtCylinderVolume.Text = "Not Applicable"
        Else
            txtCircleArea.Text = "Not Applicable"
        txtCircleVolume.Text = "Not Applicable"
            txtSphereArea.Text = "Not Applicable"
        txtSphereVolume.Text = "Not Aplicable"
            txtCylinderArea.Text = cylinder1.GetArea().ToString()
        txtCylinderVolume.Text = cylinder1.GetVolume().ToString()
        End If

    End Sub