Hello,
I am having some trouble with this code. I know that I am supposed to use an array, however I cannot figure out how to do so. This code is not giving me any output, its not taking any input, and its throwing me tons of errors I cant figure out how to get rid of. Here is the code that I presently have with the problem stated before the code in comments:
please help me?
I am having some trouble with this code. I know that I am supposed to use an array, however I cannot figure out how to do so. This code is not giving me any output, its not taking any input, and its throwing me tons of errors I cant figure out how to get rid of. Here is the code that I presently have with the problem stated before the code in comments:
Module ShapeHierarchy 'Implement a portion of the shape hierarchy shown in Fig. 10.3. 'You should implement the two-dimensional shapes Circle and Square and the three-dimensional 'shapes sphere and Cube. Each two dimensional Shape should contain method GetArea to 'calculate the area of the two-dimensional shape. Each three-dimensional shape should have methods 'GetArea and GetVolume to calculate the surface area and volume, respectively, 'of the three-dimensional shape. Use the following formulas for the area and volume of the various shapes: 'a) area of a square : side * side 'b) area of a circle: Math.PI * Radius, where radius is the radius of a circle 'c) area of a sphere: 4 * Math.PIb* Radius * Radius, where radius is the radius of a sphere 'd) volume of a sphere: (4/3) * Math.PI *Radius * Radius * Radius 'e) area of a cube: 6 * side * side 'f) voolume of a cube: side * side * side 'Create a program that uses an array of shape references to objects of each concrete class in the hierarchy. 'The program should display a string of each object. Each object's ToString method should display all of that object's data, its area and, for 'three-dimensional shapes, its volume. 'Create a console application. Prompt the user for a shape (provide a list of the shapes available) and the appropriate data needed to compute the area and/or volume. Sub Main() 'creates the screen that allows the user to select which shape they want Dim KeyPressed As ConsoleKeyInfo Console.WriteLine("Enter the Number of the Shape to be Computed") Console.WriteLine() Console.WriteLine("1) Compute the Area of a Square") Console.WriteLine("2) Compute the Area of a a Circle") Console.WriteLine("3) Compute the Area of a a Cube") Console.WriteLine("4) Compute the Area of a Sphere") Console.WriteLine("5) Compute the Voume of a Cube") Console.WriteLine("6) Compute the Volume of a Sphere") Console.WriteLine() Console.WriteLine("Press <ESC> to Quit!") Do KeyPressed = Console.ReadKey(True) Select Case KeyPressed.Key 'square area code Case ConsoleKey.D1 Dim mySquare As Square mySquare = GetSquareDetails() Console.WriteLine(mySquare.ToString) 'circle area code Case ConsoleKey.D2 Dim myCircle As Circle myCircle = GetCircleDetails() Console.WriteLine(myCircle.ToString) 'cube area code Case ConsoleKey.D3 Dim myCube As Cube myCube = GetCubeDetails() Console.WriteLine(myCube.ToString) 'sphere area code Case ConsoleKey.D4 Dim mySphere As Sphere mySphere = GetSphereDetails() Console.WriteLine(mySphere.ToString) End Select Loop While Not KeyPressed.Key = ConsoleKey.Escape End Sub 'function that gets square details Private Function GetSquareDetails() As Square 'define a new square, a string variable to get info from user, and boolean variable to check continuation Dim GetSquare As New Square Dim GetValue As String Dim ValueIsValidated As Boolean Console.WriteLine() Console.WriteLine("Enter then Size of the Sides of the Square:-") Do GetValue = Console.ReadLine() 'get input from user If Single.TryParse(GetValue, GetSquare, SizeofSide) Then ValueIsValidated = True Else 'if input is invalid tells user to enter a valid value Console.WriteLine("Please Enter a Valid Number for the Size of a Square!") End If Loop Until ValueIsValidated Return GetSquare End Function End Module 'class that defines a square Public Class Square Public Property SizeofSide As Single 'function that calculates area of square Public Function GetArea() As Single Return SizeofSide * SizeofSide End Function 'overrides the default class ToString function and creates own Public Overrides Funtion ToString() As String Return "The sides of the sides are " & SizeofSide & " and the Area of the square is " & FormatNumber(GetArea(), 4) End Function End Class 'function that gets circle details Private Function GetCircleDetails() As Circle 'define a new circle, a string variable to get info from user, and boolean variable to check continuation Dim GetCircle As New Circle Dim GetValue As String Dim ValueIsValidated As Boolean Console.WriteLine() Console.WriteLine("Enter then radius of the circle:-") Do GetValue = Console.ReadLine() 'get input from user If Single.TryParse(GetValue, GetCircle, Radius) Then ValueIsValidated = True Else 'if input is invalid tells user to enter a valid value Console.WriteLine("Please Enter a Valid Number for the Radius of a Circle!") End If Loop Until ValueIsValidated Return GetCircle End Function End Module 'class that defines a Circle Public Class Circle Public Property Radius As Single 'function that calculates area of circle Public Function GetArea() As Single Return Math.PI * Radius * Radius End Function 'overrides the default class ToString function and creates own Public Overrides Funtion ToString() As String Return "The Radius of a circle " & Radius & " and the Area of the Circle is " & FormatNumber(GetArea(), 4) End Function End Class 'function that gets cube details Private Function GetCubedetails() As Cube 'define a new cube, a string variable to get info from user, and boolean variable to check continuation Dim GetCube As New Cube Dim GetValue As String Dim ValueIsValidated As Boolean Console.WriteLine() Console.WriteLine("Enter the Side of the Cube:-") Do GetValue = Console.ReadLine() 'get input from user If Single.TryParse(GetValue, GetCube, Side) Then ValueIsValidated = True Else 'if input is invalid tells user to enter a valid value Console.WriteLine("Please Enter a Valid Number for the side of the Cube!") End If Loop Until ValueIsValidated Return GetCube End Function End Module 'class that defines a Cube Public Class Cube Public Property Side As Single 'function that calculates area of Cube Public Function GetArea() As Single Return 6 * Side * Side End Function 'overrides the default class ToString function and creates own Public Overrides Funtion ToString() As String Return "The Side of a Cube " & Side & " and the Area of the Cube is " & FormatNumber(GetArea(), 4) End Function End Class 'function that gets sphere's area details Private Function GetShperedetails() As Sphere 'define a new , a string variable to get info from user, and boolean variable to check continuation Dim GetShere As New Sphere Dim GetValue As String Dim ValueIsValidated As Boolean Console.WriteLine() Console.WriteLine("Enter the Radus of the Sphere:-") Do GetValue = Console.ReadLine() 'get input from user If Single.TryParse(GetValue, GetSphere, Radius) Then ValueIsValidated = True Else 'if input is invalid tells user to enter a valid value Console.WriteLine("Please Enter a Valid Number for the radius of the Sphere!") End If Loop Until ValueIsValidated Return GetSphere End Function End Module 'class that defines a Sphere Public Class Sphere Public Property Radius As Single 'function that calculates area of Sphere Public Function GetArea() As Single Return 4 * Math.PI * Radius End Function 'overrides the default class ToString function and creates own Public Overrides Funtion ToString() As String Return "The radius of a sphere " & Radius & " and the area of the Sphere is " & FormatNumber(GetArea(), 4) End Function End Class 'function that gets cube's volume details Private Function GetCubeVoldetails() As CubeVol 'define a new cube, a string variable to get info from user, and boolean variable to check continuation Dim GetCubeVol As New CubeVol Dim GetValue As String Dim ValueIsValidated As Boolean Console.WriteLine() Console.WriteLine("Enter the Side of the Cube:-") Do GetValue = Console.ReadLine() 'get input from user If Single.TryParse(GetValue, GetCube, Side) Then ValueIsValidated = True Else 'if input is invalid tells user to enter a valid value Console.WriteLine("Please Enter a Valid Number for the side of the Cube!") End If Loop Until ValueIsValidated Return GetCubeVol End Function End Module 'class that defines a CubeVolume Public Class CubeVol Public Property Side As Single 'function that calculates volume of Cube Public Function GetVolume() As Single Return Side * Side * Side End Function 'overrides the default class ToString function and creates own Public Overrides Funtion ToString() As String Return "The Side of a Cube " & Side & " and the Volume of the Cube is " & FormatNumber(GetArea(), 4) End Function End Class 'function that gets Sphere's volume details Private Function GetSphereVoldetails() As SphereVol 'define a new spherevol, a string variable to get info from user, and boolean variable to check continuation Dim GetSphereVol As New SphereVol Dim GetValue As String Dim ValueIsValidated As Boolean Console.WriteLine() Console.WriteLine("Enter the Radius of the Sphere:-") Do GetValue = Console.ReadLine() 'get input from user If Single.TryParse(GetValue, GetSphereVol, Radius) Then ValueIsValidated = True Else 'if input is invalid tells user to enter a valid value Console.WriteLine("Please Enter a Valid Number for the radius of the Sphere!") End If Loop Until ValueIsValidated Return GetSphereVol End Function End Module 'class that defines a Sphere's Volume Public Class SphereVol Public Property Radius As Single 'function that calculates volume of Sphere Public Function GetVolume() As Single Return (4 / 3) * Math.PI * Radius * Radius * Radius End Function 'overrides the default class ToString function and creates own Public Overrides Funtion ToString() As String Return "The Radius of a Sphere " & Sphere & " and the Volume of the Sphere is " & FormatNumber(GetArea(), 4) End Function End Class
please help me?
Last edited: