Public Class MicrowaveOven Private timeString As String = _ String.Empty ' contains time entered as a String Private cookTime As Time ' holds the time ' event handler appends 1 to time string Private Sub oneButton_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles oneButton.Click Beep() ' sound beep timeString &= "1" ' append digit to time input DisplayTime() ' display time input properly End Sub ' oneButton_Click ' event handler appends 2 to time string Private Sub twoButton_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles twoButton.Click Beep() ' sound beep timeString &= "2" ' append digit to time input DisplayTime() ' display time input properly End Sub ' twobutton_Click 'Add buttons 3 - 9 and 0... ' event handler starts the microwave oven's cooking process Private Sub startButton_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles startButton.Click Beep() timeString = String.Empty ' clear timeString for future input clockTimer.Enabled = True ' begin timer windowLabel.BackColor = Color.Yellow ' turn "light" on End Sub ' startButton_Click ' event handler to clear input Private Sub clearButton_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles clearButton.Click ' Add code to reset each method or variable to its initial setting End Sub ' clearButton_Click ' method to display formatted time in timer window Private Sub DisplayTime() Dim second As Integer Dim minute As Integer Dim hour As Integer Dim time As String ' the display String ' disallow extra input if number of hours > 9 If timeString.Length > 5 Then ' take only the first 5 digits timeString = timeString.Substring(0, 5) End If ' pad the empty spaces of the display String with "0" time = timeString.PadLeft(5, Convert.ToChar("0")) ' extract seconds and minutes and hours second = Convert.ToInt32(time.Substring(3)) minute = Convert.ToInt32(time.Substring(1, 2)) hour = Convert.ToInt32(time.Substring(0, 1)) ' create Time object to contain time entered by user cookTime = New Time(hour, minute, second) ' display number of hours, minutes, and seconds displayButton.Text = String.Format("{0:D1}:{1:D2}:{2:D2}", _ hour, minute, second) End Sub ' DisplayTime ' event handler displays new time each second Private Sub clockTimer_Tick(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles clockTimer.Tick ' perform countdown, subtract one second If cookTime.Second > 0 Then cookTime.Second -= 1 ElseIf cookTime.Minute > 0 Then cookTime.Minute -= 1 ' subtract one minute cookTime.Second = 59 ' reset seconds for new minute ElseIf cookTime.Hour > 0 Then cookTime.Hour -= 1 ' subtract one hour cookTime.Minute = 59 ' reset minutes for new hour cookTime.Second = 59 ' reset seconds for new minute Else ' no more seconds clockTimer.Enabled = False ' stop the timer Beep() ' sound beep displayButton.Text = "Done!" ' display "Done" message windowLabel.BackColor = Label.DefaultBackColor Return End If ' refresh the display time displayButton.Text = String.Format("{0:D1}:{1:D2}:{2:D2}", _ cookTime.Hour, cookTime.Minute, cookTime.Second) End Sub ' clockTimer_Tick End Class ' MicrowaveOven