Public Class ControlPanelForm
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Friend WithEvents txtClassCode As System.Windows.Forms.TextBox
    Friend WithEvents lblCodeCaption As System.Windows.Forms.Label
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents txtFirst As System.Windows.Forms.TextBox
    Friend WithEvents dtBirth As System.Windows.Forms.DateTimePicker
    Friend WithEvents txtLast As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents cmdClose As System.Windows.Forms.Button
    Friend WithEvents cmdAdd As System.Windows.Forms.Button
    Friend WithEvents lstChildren As System.Windows.Forms.ListBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents cmdGetYoungest As System.Windows.Forms.Button

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.Container

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.lstChildren = New System.Windows.Forms.ListBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.cmdAdd = New System.Windows.Forms.Button()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.cmdGetYoungest = New System.Windows.Forms.Button()
        Me.txtLast = New System.Windows.Forms.TextBox()
        Me.dtBirth = New System.Windows.Forms.DateTimePicker()
        Me.txtFirst = New System.Windows.Forms.TextBox()
        Me.txtClassCode = New System.Windows.Forms.TextBox()
        Me.lblCodeCaption = New System.Windows.Forms.Label()
        Me.cmdClose = New System.Windows.Forms.Button()
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left)
        Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label4, Me.lstChildren, Me.Label3, Me.Label1, Me.cmdAdd, Me.Label2, Me.cmdGetYoungest, Me.txtLast, Me.dtBirth, Me.txtFirst})
        Me.GroupBox1.Location = New System.Drawing.Point(8, 16)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(308, 268)
        Me.GroupBox1.TabIndex = 4
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Control Panel"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(12, 128)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(52, 12)
        Me.Label4.TabIndex = 7
        Me.Label4.Text = "Children:"
        '
        'lstChildren
        '
        Me.lstChildren.Location = New System.Drawing.Point(12, 144)
        Me.lstChildren.Name = "lstChildren"
        Me.lstChildren.Size = New System.Drawing.Size(280, 108)
        Me.lstChildren.TabIndex = 6
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(12, 92)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(36, 12)
        Me.Label3.TabIndex = 4
        Me.Label3.Text = "Date:"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(12, 36)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(36, 12)
        Me.Label1.TabIndex = 4
        Me.Label1.Text = "First:"
        '
        'cmdAdd
        '
        Me.cmdAdd.Location = New System.Drawing.Point(200, 32)
        Me.cmdAdd.Name = "cmdAdd"
        Me.cmdAdd.Size = New System.Drawing.Size(88, 20)
        Me.cmdAdd.TabIndex = 3
        Me.cmdAdd.Text = "Add Child"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(12, 64)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(36, 12)
        Me.Label2.TabIndex = 4
        Me.Label2.Text = "Last:"
        '
        'cmdGetYoungest
        '
        Me.cmdGetYoungest.Location = New System.Drawing.Point(200, 88)
        Me.cmdGetYoungest.Name = "cmdGetYoungest"
        Me.cmdGetYoungest.Size = New System.Drawing.Size(88, 20)
        Me.cmdGetYoungest.TabIndex = 5
        Me.cmdGetYoungest.Text = "Get Youngest"
        '
        'txtLast
        '
        Me.txtLast.Location = New System.Drawing.Point(60, 60)
        Me.txtLast.Name = "txtLast"
        Me.txtLast.Size = New System.Drawing.Size(112, 21)
        Me.txtLast.TabIndex = 1
        Me.txtLast.Text = ""
        '
        'dtBirth
        '
        Me.dtBirth.Format = System.Windows.Forms.DateTimePickerFormat.Short
        Me.dtBirth.Location = New System.Drawing.Point(60, 88)
        Me.dtBirth.Name = "dtBirth"
        Me.dtBirth.Size = New System.Drawing.Size(112, 21)
        Me.dtBirth.TabIndex = 2
        '
        'txtFirst
        '
        Me.txtFirst.Location = New System.Drawing.Point(60, 32)
        Me.txtFirst.Name = "txtFirst"
        Me.txtFirst.Size = New System.Drawing.Size(112, 21)
        Me.txtFirst.TabIndex = 0
        Me.txtFirst.Text = ""
        '
        'txtClassCode
        '
        Me.txtClassCode.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.txtClassCode.BackColor = System.Drawing.Color.White
        Me.txtClassCode.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtClassCode.ForeColor = System.Drawing.Color.DarkGreen
        Me.txtClassCode.Location = New System.Drawing.Point(332, 32)
        Me.txtClassCode.Multiline = True
        Me.txtClassCode.Name = "txtClassCode"
        Me.txtClassCode.ReadOnly = True
        Me.txtClassCode.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.txtClassCode.Size = New System.Drawing.Size(264, 252)
        Me.txtClassCode.TabIndex = 7
        Me.txtClassCode.Text = "Public Class NuclearFamily" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "    Public Father As Person" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "    Public Mother As Per" & _
        "son" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "    Public Children As New Collection()" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "    Public Sub New(ByVal Father," & _
        " ByVal Mother)" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "        Me.Father = Father" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "        Me.Mother = Mother" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "    End " & _
        "Sub" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "    Public Sub New()" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "    End Sub" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "    Public Function FindYoungestChil" & _
        "d() As Person" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "        Dim Child As Person" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "        Dim Youngest As Person" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "  " & _
        "      For Each Child In Children" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "            If Youngest Is Nothing Then" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "     " & _
        "           Youngest = Child" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "            ElseIf Youngest.BirthDate < Child.Birth" & _
        "Date Then" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "                Youngest = Child" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "            End If" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "        Next" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "        Return Youngest" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "    End Function" & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10) & "End Class"
        '
        'lblCodeCaption
        '
        Me.lblCodeCaption.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblCodeCaption.Location = New System.Drawing.Point(332, 12)
        Me.lblCodeCaption.Name = "lblCodeCaption"
        Me.lblCodeCaption.Size = New System.Drawing.Size(172, 20)
        Me.lblCodeCaption.TabIndex = 2
        Me.lblCodeCaption.Text = "The NuclearFamily Code:"
        '
        'cmdClose
        '
        Me.cmdClose.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
        Me.cmdClose.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.cmdClose.Location = New System.Drawing.Point(504, 300)
        Me.cmdClose.Name = "cmdClose"
        Me.cmdClose.Size = New System.Drawing.Size(92, 28)
        Me.cmdClose.TabIndex = 8
        Me.cmdClose.Text = "Close"
        '
        'ControlPanelForm
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
        Me.CancelButton = Me.cmdClose
        Me.ClientSize = New System.Drawing.Size(604, 334)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox1, Me.cmdClose, Me.lblCodeCaption, Me.txtClassCode})
        Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Name = "ControlPanelForm"
        Me.Text = "The NuclearFamily Tester"
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Family As New NuclearFamily()

    Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
        Me.Close()
    End Sub

    Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
        Family.Children.Add(New Person(txtFirst.Text, txtLast.Text, dtBirth.Value))
        lstChildren.Items.Add(txtFirst.Text & " " & txtLast.Text & " (" & Int((DateTime.Now.Subtract(dtBirth.Value)).TotalDays / 365) & " years old)")
    End Sub

    Private Sub cmdGetYoungest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetYoungest.Click
        MessageBox.Show("The youngest is " & Family.FindYoungestChild.FirstName, "Youngest Child")
    End Sub
End Class

Public Class Person

    ' Data for the Person
    Private _FirstName As String
    Private _LastName As String
    Private _BirthDate As Date

    Public Property FirstName() As String
        Get
            Return _FirstName
        End Get

        Set(ByVal Value As String)
            _FirstName = Value
        End Set
    End Property

    Public Property LastName() As String
        Get
            Return _LastName
        End Get

        Set(ByVal Value As String)
            _LastName = Value
        End Set
    End Property

    Public ReadOnly Property BirthDate() As Date
        Get
            Return _BirthDate
        End Get
    End Property

    ' Constructors.
    Public Sub New(ByVal FirstName As String, ByVal LastName As String, _
     ByVal BirthDate As Date)
        _FirstName = FirstName
        _LastName = LastName
        _BirthDate = BirthDate
    End Sub

    Public Sub New(ByVal FirstName As String, ByVal LastName As String)
        _FirstName = FirstName
        _LastName = LastName
        _BirthDate = DateTime.Now
    End Sub

    Public Sub New(ByVal FirstName As String, ByVal LastName As String, _
     ByVal Age As Integer)
        _FirstName = FirstName
        _LastName = LastName
        _BirthDate = DateTime.Now.AddYears(-Age)
    End Sub

    ' Built-in feature to get the Person object to introduce itself.
    Public Function GetIntroduction() As String
        Dim Intro As String
        Intro = "My name is " & FirstName & " " & LastName & ". "
        Intro &= "I was born on " & BirthDate.ToString
        Return Intro
    End Function

End Class

Public Class NuclearFamily
    Public Father As Person
    Public Mother As Person
    Public Children As New Collection()

    Public Sub New(ByVal Father As Person, ByVal Mother As Person)
        Me.Father = Father
        Me.Mother = Mother
    End Sub

    Public Sub New()
    End Sub

    Public Function FindYoungestChild() As Person
        Dim Child As Person
        Dim Youngest As Person

        For Each Child In Children
            If Youngest Is Nothing Then
                Youngest = Child
            ElseIf Youngest.BirthDate < Child.BirthDate Then
                Youngest = Child
            End If
        Next

        Return Youngest
    End Function

End Class

