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

7.3 Create a project to input chartering information about yachts and print a su

ID: 3556518 • Letter: 7

Question

7.3 Create a project to input chartering information about yachts and print a

summary report showing the total revenue, number of charters, and average

hours per charter.

Menus

The File menu will contain items for Print Summary, Print Yacht Types, and

Exit. Place a separator before Exit. The Edit menu should have items for

Clear for Next Charter, Add Yacht Type, Remove Yacht Type, and Display

Count of Yacht Types. Include a separator after the Clear item. The Help

menu will contain an About item that displays an About form.

The Form

Explanation / Answer

'Project: Yacht Charters
'Programmer: Michelle Smith
'Date: November 2009
'Description: Maintain a list of yacht brands and sizes; prints
' a summary report of revenue, number of charters
' and average hours per charter.
'Folder: My Project

Public Class MainForm
' Declare module-level variables.
Private TotalRevenueDecimal, AverageHoursDecimal As Decimal
Private CharterCountInteger As Integer

Private Sub AddYachtTypeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddYachtTypeToolStripMenuItem.Click
' Add a new yacht type to the yacht list.

With YachtTypeComboBox
' Test for blank input.
If .Text <> "" Then
' Make sure item is not already on the list.
Dim ItemFoundBoolean As Boolean
Dim ItemIndexInteger As Integer
Do Until ItemFoundBoolean Or ItemIndexInteger = .Items.Count
If .Text = .Items(ItemIndexInteger).ToString() Then
ItemFoundBoolean = True
Exit Do
Else
ItemIndexInteger += 1
End If
Loop
If ItemFoundBoolean Then
MessageBox.Show("Duplicate item.", "Add Failed", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
' If it's not in the list, add it.
.Items.Add(.Text)
.Text = ""
End If
Else
MessageBox.Show("Enter a yacht type to add", _
"Missing Data", MessageBoxButtons.OK, _
MessageBoxIcon.Exclamation)
End If
.Focus()
End With
End Sub

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
' End the program.

Me.Close()
End Sub

Private Sub ClearForNextCharterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearForNextCharterToolStripMenuItem.Click
' Clear all controls.
Dim ResponseDialogResult As DialogResult
ResponseDialogResult = MessageBox.Show("Clear the form?", _
"Clear all items", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If ResponseDialogResult = DialogResult.Yes Then
YachtTypeComboBox.SelectedIndex = -1
YachtSizeComboBox.SelectedIndex = -1
ResponsiblePartyTextBox.Clear()
HoursTextBox.Clear()
PriceTextBox.Clear()
End If
End Sub

Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
' Clear all controls.
Dim ResponseDialogResult As DialogResult
ResponseDialogResult = MessageBox.Show("Clear the form?", _
"Clear all items", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If ResponseDialogResult = DialogResult.Yes Then
YachtTypeComboBox.SelectedIndex = -1
YachtSizeComboBox.SelectedIndex = -1
ResponsiblePartyTextBox.Clear()
HoursTextBox.Clear()
PriceTextBox.Clear()
End If
End Sub

Private Sub OkButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OkButton.Click
Dim PriceInteger, HoursInteger, TotalHoursInteger As Integer

Try
HoursInteger = Integer.Parse(HoursTextBox.Text)

With YachtSizeComboBox
If .SelectedIndex = -1 Then
MessageBox.Show("Enter a yacht size", _
"Missing Data", MessageBoxButtons.OK, _
MessageBoxIcon.Exclamation)
Exit Sub

Else

CharterCountInteger += 1

If .SelectedIndex = 0 Then
PriceInteger = HoursInteger * 95D
ElseIf .SelectedIndex = 1 Then
PriceInteger = HoursInteger * 137D
ElseIf .SelectedIndex = 2 Then
PriceInteger = HoursInteger * 160D
ElseIf .SelectedIndex = 3 Then
PriceInteger = HoursInteger * 192D
ElseIf .SelectedIndex = 4 Then
PriceInteger = HoursInteger * 250D
ElseIf .SelectedIndex = 5 Then
PriceInteger = HoursInteger * 400D
ElseIf .SelectedIndex = 6 Then
PriceInteger = HoursInteger * 550D

   End If
End If

End With

PriceTextBox.Text = PriceInteger.ToString("C")
If CharterCountInteger > 0 Then
' Calculate the average.

AverageHoursDecimal = TotalHoursInteger / CharterCountInteger
Else
MessageBox.Show("No sales data to summarize.", "Average Charter Summary", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

  

Catch QuantityException As FormatException
MessageBox.Show("Quantity must be numeric.", "Data entry error", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
With HoursTextBox
.Focus()
.SelectAll()
End With
End Try
TotalRevenueDecimal += PriceInteger
TotalHoursInteger += HoursInteger
  
End Sub
  

Private Sub PrintSummaryPrintDocument_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintSummaryPrintDocument.PrintPage
' Handle printing and print preview when printing page.
Dim PrintFont As New Font("Arial", 12)
Dim HeadingFont As New Font("Arial", 14, FontStyle.Bold)
Dim LineHeightSingle As Single = PrintFont.GetHeight + 2
Dim HorizontalPrintLocationSingle As Single = e.MarginBounds.Left
Dim VerticalPrintLocationSingle As Single = e.MarginBounds.Top

' Set up and display heading lines.
e.Graphics.DrawString("Charter Summary", HeadingFont, _
Brushes.Black, HorizontalPrintLocationSingle, VerticalPrintLocationSingle)
VerticalPrintLocationSingle += LineHeightSingle
e.Graphics.DrawString("by Michelle Smith", HeadingFont, _
Brushes.Black, HorizontalPrintLocationSingle, VerticalPrintLocationSingle)
VerticalPrintLocationSingle += LineHeightSingle
e.Graphics.DrawString("Total Revenue: " & TotalRevenueDecimal.ToString("C"), PrintFont, _
Brushes.Black, 600, HorizontalPrintLocationSingle)

VerticalPrintLocationSingle += LineHeightSingle * 2
e.Graphics.DrawString("Total Number of Charters: " & CharterCountInteger.ToString(), PrintFont, _
Brushes.Black, 600, HorizontalPrintLocationSingle)
VerticalPrintLocationSingle += LineHeightSingle * 2
e.Graphics.DrawString("Average Hours Chartered: " & AverageHoursDecimal.ToString("D2"), PrintFont, _
Brushes.Black, 600, HorizontalPrintLocationSingle)


End Sub


Private Sub PrintSummaryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintSummaryToolStripMenuItem.Click
' Assign the PrintSummaryPrintDocument to the preview.

PrintPreviewDialog1.Document = PrintSummaryPrintDocument
' Show the dialog.
PrintPreviewDialog1.ShowDialog()
End Sub
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