Need help with this program please!

Hello! I am working on the following assignment: Modify a program that I had already written to provide a method NextDay to increment the day by one. The cDateCheckChange object should always stay in the constant state. Then write a program that tests the NextDay method in a loop that prints the date during each iteration of the loop to illustrate that the NextDay method works correctly. Be sure to test the following cases: a)Incrementing into the next month b)Incrementing into the next year

I have pasted my code below. I know that in the cDateCheckChange class, everything except the NextDay method works fine, so that must be where my problem is. If you could please tell me what I have done wrong, I would really appreciate it! Thanks for your time and help!

Linda

Here is the cDateCheckChange class code:

Public Class cDateCheckChange
Inherits Object

Private mMonth As Integer ' 1-12
Private mDay As Integer ' 1-31 based on month
Private mYear As Integer ' any year

' constructor confirms proper value for month, then calls
' method CheckDay to confirm proper value for day
Public Sub New(ByVal monthValue As Integer, _
ByVal dayValue As Integer, ByVal yearValue As Integer)
Dim counter As Integer
counter = 0
' ensure month value is valid
If (monthValue > 0 AndAlso monthValue <= 12) Then
mMonth = monthValue
Else
mMonth = 1

' inform user of error
Dim errorMessage As String = _
"Month invalid. Set to month 1."

MessageBox.Show(errorMessage, "", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

mYear = yearValue
mDay = CheckDay(dayValue) ' validate day

While counter <> 10
NextDay(mYear, mDay, mMonth)
counter = counter + 1
End While

End Sub ' New

' confirm proper day value based on month and year
Private Function CheckDay(ByVal testDayValue As Integer) _
As Integer

Dim daysPerMonth() As Integer = _
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}

If (testDayValue > 0 AndAlso _
testDayValue <= daysPerMonth(mMonth)) Then

Return testDayValue
End If

' check for leap year in February
If (mMonth = 2 AndAlso testDayValue = 29 AndAlso _
mYear Mod 400 = 0 OrElse mYear Mod 4 = 0 AndAlso _
mYear Mod 100 <> 0) Then

Return testDayValue
Else

' inform user of error
Dim errorMessage As String = _
"day " & testDayValue & "invalid. Set to day 1. "

MessageBox.Show(errorMessage, "", _
MessageBoxButtons.OK, MessageBoxIcon.Error)

Return 1 ' leave object in consistent state
End If

End Function ' CheckDay

' create string containing month/day/year format
Public Function ToStandardString() As String
Return mMonth & "/" & mDay & "/" & mYear
End Function ' ToStandardString

Public Function NextDay(ByVal mDay As Integer, ByVal mMonth As Integer, ByVal mYear As Integer) As String

If mMonth = 1 AndAlso mDay = 32 Then
mMonth += 1
mDay = 1
Return mMonth & "/" & mDay & "/" & mYear
Else
Return mMonth & "/" & mDay & "/" & mYear
End If

If (mMonth = 2 AndAlso mDay = 29 AndAlso mYear Mod 400 = 0 OrElse mYear Mod 4 = 0 AndAlso mYear Mod 100 <> 0) Then
mMonth += 1
mDay = 1
Return mMonth & "/" & mDay & "/" & mYear
ElseIf mMonth = 2 AndAlso mDay = 29 Then
mMonth += 1
mDay = 1
End If

If mMonth = 3 AndAlso mDay = 32 Then
mMonth += 1
mDay = 1
Return mMonth & "/" & mDay & "/" & mYear
Else
Return mMonth & "/" & mDay & "/" & mYear
End If

If mMonth = 4 AndAlso mDay = 31 Then
mMonth += 1
mDay = 1
Return mMonth & "/" & mDay & "/" & mYear
Else
Return mMonth & "/" & mDay & "/" & mYear
End If

If mMonth = 5 AndAlso mDay = 32 Then
mMonth += 1
mDay = 1
Return mMonth & "/" & mDay & "/" & mYear
Else
Return mMonth & "/" & mDay & "/" & mYear
End If

If mMonth = 6 AndAlso mDay = 31 Then
mMonth += 1
mDay = 1
Return mMonth & "/" & mDay & "/" & mYear
Else
Return mMonth & "/" & mDay & "/" & mYear
End If

If mMonth = 7 AndAlso mDay = 32 Then
mMonth += 1
mDay = 1
Return mMonth & "/" & mDay & "/" & mYear
Else
Return mMonth & "/" & mDay & "/" & mYear
End If

If mMonth = 8 AndAlso mDay = 32 Then
mMonth += 1
mDay = 1
Return mMonth & "/" & mDay & "/" & mYear
Else
Return mMonth & "/" & mDay & "/" & mYear
End If

If mMonth = 9 AndAlso mDay = 31 Then
mMonth += 1
mDay = 1
Return mMonth & "/" & mDay & "/" & mYear
Else
Return mMonth & "/" & mDay & "/" & mYear
End If

If mMonth = 10 AndAlso mDay = 32 Then
mMonth += 1
mDay = 1
Return mMonth & "/" & mDay & "/" & mYear
Else
Return mMonth & "/" & mDay & "/" & mYear
End If

If mMonth = 11 AndAlso mDay = 31 Then
mMonth += 1
mDay = 1
Return mMonth & "/" & mDay & "/" & mYear
Else
Return mMonth & "/" & mDay & "/" & mYear
End If

If mMonth = 12 AndAlso mDay = 31 Then
mMonth += 1
mDay = 1
mYear += 1
Return mMonth & "/" & mDay & "/" & mYear
Else
Return mMonth & "/" & mDay & "/" & mYear
End If

End Function


End Class

And here is the program code:
Public Class Form1
Inherits System.Windows.Forms.Form


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dateChange As cDateCheckChange
Dim output As String

dateChange = New cDateCheckChange(Me.DayBox.Text, Me.MonthBox.Text, Me.YearBox.Text)
output = dateChange.ToStandardString

Me.outputBox.Text = output

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.DayBox.Text = " "
Me.MonthBox.Text = " "
Me.YearBox.Text = " "
Me.outputBox.Text = " "

End Sub
End Class


Thanks Again!!!!


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories