Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Visual Basic help please. Exercise 9-1 Calculate reservation totals In this exercise, youll add code that calculates the number of nights, total price, and average

Visual Basic help please.

Exercise 9-1 Calculate reservation totals In this exercise, youll add code that calculates the number of nights, total price, and average price for a reservation based on the arrival and departure dates the user enters. image text in transcribed Open the project and implement the calculations

1. Open the Reservations project in the Assignment Exercises\Chapter 09\Reservations directory.

2. Add code to get the arrival and departure dates the user enters when the user clicks the Calculate button. Then, calculate the number of days between those dates, calculate the total price based on a price per night of $160, calculate the average price per night, and display the results.

3. Test the application to be sure it works correctly. At this point, the average price will be the same as the nightly price.

Enhance the way the form works

4. Add an event handler for the Load event of the form. This event handler should get the current date and three days after the current date and assign these dates to the Arrival Date and Departure Date text boxes as default values. Be sure to format the dates as shown above.

5. Modify the code so Friday and Saturday nights are charged at $180 and other nights are charged at $160. One way to do this is to use a while loop that checks the day for each date of the reservation.

6. Test the application to be sure that the default dates are displayed correctly and that the totals are calculated correctly.

Add code to validate the dates

7. Add code to the IsDateTime method to check that the arrival and departure dates are valid dates.

8. Add code to the IsWithinRange method to check that the arrival and departure dates are within a range that includes the minimum and maximum dates that are passed to it.

9. Add code to the IsValidData method that uses the IsPresent, IsDateTime, and IsWithinRange methods to validate the arrival and departure dates. These dates should be in a range from the current date to five years after the current date.

10. Add code that uses the IsValidData method to validate the arrival and departure dates. In addition, add code to check that the departure date is after the arrival date.

11. Test the application to be sure the dates are validated properly.

This is the code I have so far:

Public Class Form1

Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click Dim arrivalDate As Date = DateTime.Parse(txtArrivalDate.Text) Dim departureDate As Date = DateTime.Parse(txtDepartureDate.Text) Dim nights As TimeSpan = departureDate - arrivalDate Dim avgPrice As Integer = 160 Dim totalPrice As Integer = 0

txtNights.Text = nights.ToString txtAvgPrice.Text = avgPrice.ToString

End Sub

Public Function IsValidData() As Boolean

End Function

Public Function IsPresent(textbox As TextBox, name As String) _ As Boolean If textbox.Text = "" Then MessageBox.Show(name & " is a required field.", "Entry Error") textbox.Select() Return False Else Return True End If End Function

Public Function IsDateTime(textbox As TextBox, name As String) _ As Boolean

End Function

Public Function IsWithinRange(textbox As TextBox, name As String, ByVal min As Date, ByVal max As Date) As Boolean

End Function

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Me.Close() End Sub

Thank you for your help!

Reservations Anmval date: 10/18/2016 Departure date: 10/21/2016 Number of nights: 3 Total price: $480.00 Calculate Reservations Anmval date: 10/18/2016 Departure date: 10/21/2016 Number of nights: 3 Total price: $480.00 Calculate

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

5. Prepare a plan of action and execute itstarting now!

Answered: 1 week ago