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

For this project, you’ll create a form that accepts an arrival and departure d

ID: 3759374 • Letter: F

Question

For this project, you’ll create a form that accepts an arrival and departure date for a reservation from the user and then calculates the number of nights and the total price for the reservation.

The design of the Reservations form

Operation

The user enters an arrival date and a departure date and clicks the Calculate button or presses the Enter key.

The application calculates, formats, and displays the number of nights and the total price.

Specifications

The price per night should be $115.

This application should validate both entries to make sure they are dates that are on or after the current date. The application should also validate the departure date to be sure that it is after the arrival date.

This application should only accept reservations within five years of the current date.

When the application starts, it should display the current date in the first text box and the current date plus three days in the second text box. That way, the user can modify these default dates as necessary.

Explanation / Answer

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace daniweb
{
public partial class frmReservations : Form
{
const int PRICE_PER_DAY = 115;
public frmReservations()
{
InitializeComponent();
}
private void frmReservations_Load(object sender, EventArgs e)
{
textBoxDepart.Text = DateTime.Today.ToString("d");
textBoxArrive.Text = DateTime.Today.AddDays(3).ToString("d");
}
private void btnOk_Click(object sender, EventArgs e)
{
DateTime dtDepart;
DateTime dtArrive;
if (string.IsNullOrEmpty(textBoxDepart.Text) || !DateTime.TryParse(textBoxDepart.Text, out dtDepart))
{
MessageBox.Show("Invalid departure date!");
return;
}
if (string.IsNullOrEmpty(textBoxArrive.Text) ||!DateTime.TryParse(textBoxArrive.Text, out dtArrive))
{
MessageBox.Show("Invalid arrival date!");
return;
}
dtDepart = dtDepart.Date; //Trim off the time portion if they entered it
dtArrive = dtArrive.Date;
if (dtDepart < DateTime.Today)
{
MessageBox.Show("The departure date cannot be before today");
return;
}

if (dtArrive < dtDepart)
{
MessageBox.Show("The departure date cannot be before the departure date");
return;
}

DateTime dtUpperBoundary = DateTime.Today.AddDays(365 * 5);
if (dtDepart > dtUpperBoundary)
{
MessageBox.Show("The departure date is more than 5 years in the future");
return;
}
if (dtArrive > dtUpperBoundary)
{
MessageBox.Show("The arrival date is more than 5 years in the future");
return;
}
if (dtArrive == dtDepart)
{
MessageBox.Show("You cannot depart and arrive on the same date");
return;
}
  
int duration = Convert.ToInt32(Math.Ceiling(Math.Abs(dtArrive.Subtract(dtDepart).TotalDays))) + 1;
int price = duration * PRICE_PER_DAY;
string sNumberOfDays = duration.ToString();
string sArrivalDate = dtArrive.ToString("d");
string sDeparture = dtDepart.ToString("d");
string sTotalPrice = price.ToString("C2");
StringBuilder sb = new StringBuilder();
sb.AppendLine("Number of days: " + sNumberOfDays);
sb.AppendLine("Arrival Date: " + sArrivalDate);
sb.AppendLine("Departure Date: " + sDeparture);
sb.AppendLine("Total Price: " + sTotalPrice);
MessageBox.Show(sb.ToString());
//MessageBox.Show(string.Format("The price will be {0:C2}", price));
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}

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