Exercise
ArrayList of Points
Objetive
Create a structure named "Point3D" to represent a point in 3D space with coordinates X, Y, and Z.
Create a program that has a menu where the user can:
Add data for one point
Display all the entered points
Exit the program
The program should use ArrayLists instead of arrays.
Code
Imports System
Imports System.Collections
Namespace Point3D
Class Program
Structure Point3D
Private x, y, z As Double
End Structure
Private Shared Sub Main(ByVal args As String())
Dim [exit] As Boolean = False
Dim list As ArrayList = New ArrayList()
Dim points As Point3D = New Point3D()
Dim answer As String
Do
Console.WriteLine("1. Add data for one point")
Console.WriteLine("2. Display all the entered points")
Console.WriteLine("x. Display all the entered points")
Console.WriteLine()
Console.Write("Enter a option: ")
answer = Console.ReadLine()
If answer.ToLower() = "x" Then
[exit] = True
ElseIf answer = "1" Then
Console.Write("Point x: ")
list.Add(Convert.ToInt32(Console.ReadLine()))
Console.Write("Point y: ")
list.Add(Convert.ToInt32(Console.ReadLine()))
Console.Write("Point z: ")
list.Add(Convert.ToInt32(Console.ReadLine()))
End If
Loop While Not [exit]
End Sub
End Class
End Namespace