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

In my youth, long before personal computers, there was a company called E.S.R.,

ID: 3596995 • Letter: I

Question

In my youth, long before personal computers, there was a company called E.S.R., Inc. that satisfied my desire to possess a computing device. They had three offerings: DR. NIM, DIGI-COMP I, and THINK-A-DOT. I owned them all, but my personal favorite was THINK-A-DOT. At the time it cost a mere $2.95, which was well within my monthly allowance. I recently saw one selling on eBay for $120. Since I no longer own my original machine, and cannot afford to replace it, I would like you to build me a virtual THINK-A-DOT in Visual Basic.

As originally constructed, a marble could be dropped into one of three holes in the top of the machine. It would then percolate through the machine and come out a hole on the bottom left or right. This was to allow for two-person competition, and really was of no interest to me. As the marble percolated through the machine it caused any dot it passed to change color from yellow to blue, and from blue to yellow. The color of the dot also controlled whether the marble would fall to the left (yellow) or to the right (blue). This meant there were ten possible paths through the machine from top to bottom, flipping either two or three dots to their alternate colors along the way. The initial pattern could be reset at any time by tilting the machine to the left or right.

ThinkaDot.exe provides a workign example, if the following explanation is hard to understand. For your virtual machine, you will need some way to reset all the dots to yellow, some way to indicate the initital starting point of a virtual marable (left, middle, or right), and some way to represent the eight dots and change their color from yellow to blue or from blue to yellow. The logic is such that after changing a dot from yellow to blue, the next dot to be reversed is down and to the left.

For a blue dot changing to yellow, the next dot to be reversed is down and to the right. A virtual marble dropping down the far left or far right side will only reverse two dots and not three. The folder, ThinkaDot, contains the start of a solution. It provides a picture of the machine, and a flipper control that can be dragged onto the picture just like any other control. The flipper control has a Boolean property, droppedLeft, that tells you the direction the ball fell; and two methods: flip that reverses the control, and reset.

  A useful property of Think-a-Dot that can be used for testing, is that a marble dropped into any one of the three holes at the top, eight times in a row, will return the machine to the original pattern. Also, dropping a marble into each of the holes twice will return the machine to the original pattern.

ThinkADot Left Middle Right Reset

Explanation / Answer

Form1.vb
-------------------------------------------------------------------------
Public Class Form1
    'Declares counter variables for each button
    Private count_left = 0, count_mid = 0, count_right = 0


    Private Sub Left_Button_Click(sender As Object, e As EventArgs) Handles Left_Button.Click
        ' If clicked once, Highlight 1,4,7 // if twice Highlight 1,4,6 // 1,6
        ' Create counter to keep track

        If count_left = 0 Then
            Reset()
            Flipper1.flip()
            Flipper4.flip()
            Flipper7.flip()
            count_left = count_left + 1
        ElseIf count_left = 1 Then
            Reset()
            Flipper1.flip()
            Flipper4.flip()
            Flipper6.flip()
            count_left = count_left + 1
        ElseIf count_left = 2 Then
            Reset()
            Flipper1.flip()
            Flipper6.flip()
            count_left = 0
        End If


    End Sub

    Private Sub Middle_Button_Click(sender As Object, e As EventArgs) Handles Middle_Button.Click
        ' Possible Combinations
        '- 2,4,6 |2,5,8 |2,4,7|2,5,7|2,7

        If count_mid = 0 Then
            Reset()
            Flipper2.flip()
            Flipper4.flip()
            Flipper6.flip()
            count_mid = count_mid + 1
        ElseIf count_mid = 1 Then
            Reset()
            Flipper2.flip()
            Flipper5.flip()
            Flipper8.flip()
            count_mid = count_mid + 1
        ElseIf count_mid = 2 Then
            Reset()
            Flipper2.flip()
            Flipper4.flip()
            Flipper7.flip()
            count_mid = count_mid + 1
        ElseIf count_mid = 3 Then
            Reset()
            Flipper2.flip()
            Flipper5.flip()
            Flipper7.flip()
            count_mid = count_mid + 1
        ElseIf count_mid = 4 Then
            Reset()
            Flipper2.flip()
            Flipper7.flip()
            count_mid = 0
        End If
    End Sub

    Private Sub Right_Button_Click(sender As Object, e As EventArgs) Handles Right_Button.Click
        ' Possible Combinations
        ' - 3,5,7 | 3,5,8|3,8
        If count_right = 0 Then
            Reset()
            Flipper3.flip()
            Flipper5.flip()
            Flipper7.flip()
            count_right = count_right + 1
        ElseIf count_right = 1 Then
            Reset()
            Flipper3.flip()
            Flipper8.flip()
            count_right = count_right + 1
        ElseIf count_right = 2 Then
            Reset()
            Flipper3.flip()
            Flipper5.flip()
            Flipper8.flip()
            count_right = 0
        End If
    End Sub

    Private Sub Reset_Button_Click(sender As Object, e As EventArgs) Handles Reset_Button.Click
        ' Sets color of all dots back to default
        Reset()
    End Sub
    Private Sub Reset()
        Flipper1.reset()
        Flipper2.reset()
        Flipper3.reset()
        Flipper4.reset()
        Flipper5.reset()
        Flipper6.reset()
        Flipper7.reset()
        Flipper8.reset()
    End Sub
End Class
-------------------------------------------------------------------------------------------------
Form1.Designer.vb
--------------------------------------------------
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()>
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

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

    '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()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
        Me.Left_Button = New System.Windows.Forms.Button()
        Me.Middle_Button = New System.Windows.Forms.Button()
        Me.Right_Button = New System.Windows.Forms.Button()
        Me.Reset_Button = New System.Windows.Forms.Button()
        Me.Flipper1 = New My_Think_a_Dot.Flipper()
        Me.Flipper2 = New My_Think_a_Dot.Flipper()
        Me.Flipper3 = New My_Think_a_Dot.Flipper()
        Me.Flipper4 = New My_Think_a_Dot.Flipper()
        Me.Flipper5 = New My_Think_a_Dot.Flipper()
        Me.Flipper7 = New My_Think_a_Dot.Flipper()
        Me.Flipper8 = New My_Think_a_Dot.Flipper()
        Me.Flipper6 = New My_Think_a_Dot.Flipper()
        Me.SuspendLayout()
        '
        'Left_Button
        '
        Me.Left_Button.Location = New System.Drawing.Point(118, 36)
        Me.Left_Button.Name = "Left_Button"
        Me.Left_Button.Size = New System.Drawing.Size(62, 22)
        Me.Left_Button.TabIndex = 0
        Me.Left_Button.Text = "Left"
        Me.Left_Button.UseVisualStyleBackColor = True
        '
        'Middle_Button
        '
        Me.Middle_Button.Location = New System.Drawing.Point(239, 36)
        Me.Middle_Button.Name = "Middle_Button"
        Me.Middle_Button.Size = New System.Drawing.Size(62, 22)
        Me.Middle_Button.TabIndex = 1
        Me.Middle_Button.Text = "Middle"
        Me.Middle_Button.UseVisualStyleBackColor = True
        '
        'Right_Button
        '
        Me.Right_Button.Location = New System.Drawing.Point(357, 36)
        Me.Right_Button.Name = "Right_Button"
        Me.Right_Button.Size = New System.Drawing.Size(62, 22)
        Me.Right_Button.TabIndex = 2
        Me.Right_Button.Text = "Right"
        Me.Right_Button.UseVisualStyleBackColor = True
        '
        'Reset_Button
        '
        Me.Reset_Button.Location = New System.Drawing.Point(234, 351)
        Me.Reset_Button.Name = "Reset_Button"
        Me.Reset_Button.Size = New System.Drawing.Size(62, 22)
        Me.Reset_Button.TabIndex = 3
        Me.Reset_Button.Text = "RESET"
        Me.Reset_Button.UseVisualStyleBackColor = True
        '
        'Flipper1
        '
        Me.Flipper1.BackColor = System.Drawing.Color.Transparent
        Me.Flipper1.Location = New System.Drawing.Point(118, 85)
        Me.Flipper1.Name = "Flipper1"
        Me.Flipper1.Size = New System.Drawing.Size(34, 34)
        Me.Flipper1.TabIndex = 4
        '
        'Flipper2
        '
        Me.Flipper2.BackColor = System.Drawing.Color.Transparent
        Me.Flipper2.Location = New System.Drawing.Point(245, 85)
        Me.Flipper2.Name = "Flipper2"
        Me.Flipper2.Size = New System.Drawing.Size(34, 34)
        Me.Flipper2.TabIndex = 5
        '
        'Flipper3
        '
        Me.Flipper3.BackColor = System.Drawing.Color.Transparent
        Me.Flipper3.Location = New System.Drawing.Point(371, 85)
        Me.Flipper3.Name = "Flipper3"
        Me.Flipper3.Size = New System.Drawing.Size(34, 34)
        Me.Flipper3.TabIndex = 6
        '
        'Flipper4
        '
        Me.Flipper4.BackColor = System.Drawing.Color.Transparent
        Me.Flipper4.Location = New System.Drawing.Point(181, 168)
        Me.Flipper4.Name = "Flipper4"
        Me.Flipper4.Size = New System.Drawing.Size(34, 34)
        Me.Flipper4.TabIndex = 9
        '
        'Flipper5
        '
        Me.Flipper5.BackColor = System.Drawing.Color.Transparent
        Me.Flipper5.Location = New System.Drawing.Point(308, 168)
        Me.Flipper5.Name = "Flipper5"
        Me.Flipper5.Size = New System.Drawing.Size(34, 34)
        Me.Flipper5.TabIndex = 8
        '
        'Flipper7
        '
        Me.Flipper7.BackColor = System.Drawing.Color.Transparent
        Me.Flipper7.Location = New System.Drawing.Point(245, 249)
        Me.Flipper7.Name = "Flipper7"
        Me.Flipper7.Size = New System.Drawing.Size(34, 34)
        Me.Flipper7.TabIndex = 12
        '
        'Flipper8
        '
        Me.Flipper8.BackColor = System.Drawing.Color.Transparent
        Me.Flipper8.Location = New System.Drawing.Point(371, 249)
        Me.Flipper8.Name = "Flipper8"
        Me.Flipper8.Size = New System.Drawing.Size(34, 34)
        Me.Flipper8.TabIndex = 11
        '
        'Flipper6
        '
        Me.Flipper6.BackColor = System.Drawing.Color.Transparent
        Me.Flipper6.Location = New System.Drawing.Point(118, 249)
        Me.Flipper6.Name = "Flipper6"
        Me.Flipper6.Size = New System.Drawing.Size(34, 34)
        Me.Flipper6.TabIndex = 10
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
        Me.ClientSize = New System.Drawing.Size(544, 442)
        Me.Controls.Add(Me.Flipper7)
        Me.Controls.Add(Me.Flipper8)
        Me.Controls.Add(Me.Flipper6)
        Me.Controls.Add(Me.Flipper4)
        Me.Controls.Add(Me.Flipper5)
        Me.Controls.Add(Me.Flipper3)
        Me.Controls.Add(Me.Flipper2)
        Me.Controls.Add(Me.Flipper1)
        Me.Controls.Add(Me.Reset_Button)
        Me.Controls.Add(Me.Right_Button)
        Me.Controls.Add(Me.Middle_Button)
        Me.Controls.Add(Me.Left_Button)
        Me.Name = "Form1"
        Me.Text = "ThinkADot"
        Me.ResumeLayout(False)

    End Sub

    Friend WithEvents Left_Button As Button
    Friend WithEvents Middle_Button As Button
    Friend WithEvents Right_Button As Button
    Friend WithEvents Reset_Button As Button
    Friend WithEvents Flipper1 As Flipper
    Friend WithEvents Flipper2 As Flipper
    Friend WithEvents Flipper3 As Flipper
    Friend WithEvents Flipper4 As Flipper
    Friend WithEvents Flipper5 As Flipper
    Friend WithEvents Flipper7 As Flipper
    Friend WithEvents Flipper8 As Flipper
    Friend WithEvents Flipper6 As Flipper
End Class
------------------------------------------------------------------------------------------------------------------
Flipper.vb
--------------------------------------------------------
Public Class Flipper
    Private droppedLeftBoolean As Boolean = False

    ReadOnly Property droppedLeft() As Boolean      ' example: If Flipper1.droppedLeft then...
        Get
            Return droppedLeftBoolean   'do flip before reading
        End Get
    End Property

    Public Sub flip()                               ' example: Flipper1.flip()
        droppedLeftBoolean = Not droppedLeftBoolean
        Dot.ImageIndex = 1 - Dot.ImageIndex 'alternate dot color
    End Sub

    Public Sub reset()                              ' example: Flipper1.reset()
        Dot.ImageIndex = 0              'reset image to yellow dot
        droppedLeftBoolean = False      'default direction
    End Sub

End Class
-----------------------------------------------------------------------------------------------------
Flipper.designer.vb
-----------------------------------------------------------
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Flipper
    Inherits System.Windows.Forms.UserControl

    'UserControl overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

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

    '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.components = New System.ComponentModel.Container()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Flipper))
        Me.Dot = New System.Windows.Forms.Label()
        Me.DotImageList = New System.Windows.Forms.ImageList(Me.components)
        Me.SuspendLayout()
        '
        'Dot
        '
        Me.Dot.ImageIndex = 0
        Me.Dot.ImageList = Me.DotImageList
        Me.Dot.Location = New System.Drawing.Point(0, 0)
        Me.Dot.Name = "Dot"
        Me.Dot.Size = New System.Drawing.Size(32, 32)
        Me.Dot.TabIndex = 0
        '
        'DotImageList
        '
        Me.DotImageList.ImageStream = CType(resources.GetObject("DotImageList.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.DotImageList.TransparentColor = System.Drawing.Color.Transparent
        Me.DotImageList.Images.SetKeyName(0, "yellowdot.ico")
        Me.DotImageList.Images.SetKeyName(1, "bluedot.ico")
        '
        'Flipper
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.Controls.Add(Me.Dot)
        Me.Name = "Flipper"
        Me.Size = New System.Drawing.Size(34, 34)
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents Dot As System.Windows.Forms.Label
    Friend WithEvents DotImageList As System.Windows.Forms.ImageList

End Class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote