In: Computer Science
***IN C# ONLY, USING WINDOWS FORMS*** --NO JAVA--.
Create a GUI application in C# that calculates and displays the total travel expenses of a business person on a trip. Here is the information that the user must provide:
• Number of days on the trip • Amount of airfare, if any
• Amount of car rental fees, if any
• Number of miles driven, if a private vehicle was used
• Amount of parking fees, if any
• Amount of taxi charges, if any
• Conference or seminar registration fees, if any
• Lodging charges, per night
The company reimburses travel expenses according to the following policy:
• $37 per day for meals
• Parking fees, up to $10.00 per day
• Taxi charges up to $20.00 per day
• Lodging charges up to $95.00 per day
• If a private vehicle is used, $0.27 per mile driven.
The application should calculate and display the following:
• Total expenses incurred by the businessperson
• The total allowable expenses for the trip
• The excess that must be paid by the businessperson, if any
• The amount saved by the businessperson if the expenses were under the total allowed
In case of any query do comment. Thanks
Code:
=======ExpenseForm.cs========
using System;
using System.Windows.Forms;
namespace CalculateTravelExpense
{
public partial class ExpenseForm : Form
{
const double PerDayMeal = 37.00;
const double PerDayParking = 10.00;
const double PerDayTaxi = 20.00;
const double PerDayLodgingCharge = 95.00;
const double CostPerMile = 0.27;
int days = 0;
double airfareAmount = 0.0;
double carRentalAmount = 0.0;
double parkingAmount = 0.0;
double taxiCharge = 0.0;
double conferenceFees = 0.0;
double lodgingCharge = 0.0;
double miles = 0.0;
double totalExpense = 0.0;
double allowableExpense = 0.0;
double excessExpense = 0.0;
public ExpenseForm()
{
InitializeComponent();
}
/// <summary>
/// handles click of calculate button
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCalculate_Click(object sender, EventArgs e)
{
//load values from text box to variables
days = int.Parse(txtDayTrip.Text);
airfareAmount = double.Parse(txtAirfareAmount.Text);
carRentalAmount = double.Parse(txtCarRentalFees.Text);
miles = double.Parse(txtMiles.Text);
parkingAmount = double.Parse(txtParking.Text);
taxiCharge = double.Parse(txtTaxiCharge.Text);
conferenceFees = double.Parse(txtConferenceFees.Text);
lodgingCharge = double.Parse(txtLodgingFees.Text);
//expenses incurred by business man
totalExpense = airfareAmount + carRentalAmount + (miles * CostPerMile) + parkingAmount + taxiCharge + conferenceFees + lodgingCharge;
//allowable expense as given, airfare will be considered as one time and it would be allowed
allowableExpense = airfareAmount + (PerDayMeal + PerDayParking + PerDayTaxi + PerDayLodgingCharge) * days + (miles * CostPerMile);
txtTotalExpenses.Text = totalExpense.ToString("C");
txtAllowedExpenses.Text = allowableExpense.ToString("C");
excessExpense = totalExpense - allowableExpense;
//calculate excess expense if any, if excess expense is greater than 0 then business man has to pay otherwise he saved the amount
if (excessExpense > 0)
{
txtExcessAmount.Text = excessExpense.ToString("C");
txtSavedAmount.Clear();
}
else
{
txtSavedAmount.Text = (excessExpense * -1).ToString("C");
txtExcessAmount.Clear();
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnReset_Click(object sender, EventArgs e)
{
txtDayTrip.Clear();
txtAirfareAmount.Clear();
txtCarRentalFees.Clear();
txtConferenceFees.Clear();
txtAllowedExpenses.Clear();
txtExcessAmount.Clear();
txtLodgingFees.Clear();
txtMiles.Clear();
txtParking.Clear();
txtSavedAmount.Clear();
txtTaxiCharge.Clear();
txtTotalExpenses.Clear();
}
}
}
=========ExpenseForm.Designer.cs=============
namespace CalculateTravelExpense
{
partial class ExpenseForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblDays = new System.Windows.Forms.Label();
this.lblAirfare = new System.Windows.Forms.Label();
this.lblCar = new System.Windows.Forms.Label();
this.lblMiles = new System.Windows.Forms.Label();
this.lblParking = new System.Windows.Forms.Label();
this.lblTaxi = new System.Windows.Forms.Label();
this.lblSeminar = new System.Windows.Forms.Label();
this.lblLodging = new System.Windows.Forms.Label();
this.txtDayTrip = new System.Windows.Forms.TextBox();
this.txtAirfareAmount = new System.Windows.Forms.TextBox();
this.txtCarRentalFees = new System.Windows.Forms.TextBox();
this.txtMiles = new System.Windows.Forms.TextBox();
this.txtParking = new System.Windows.Forms.TextBox();
this.txtTaxiCharge = new System.Windows.Forms.TextBox();
this.txtConferenceFees = new System.Windows.Forms.TextBox();
this.txtLodgingFees = new System.Windows.Forms.TextBox();
this.lblExpense = new System.Windows.Forms.Label();
this.lblAllowedExpense = new System.Windows.Forms.Label();
this.label11 = new System.Windows.Forms.Label();
this.label12 = new System.Windows.Forms.Label();
this.txtTotalExpenses = new System.Windows.Forms.TextBox();
this.txtAllowedExpenses = new System.Windows.Forms.TextBox();
this.txtExcessAmount = new System.Windows.Forms.TextBox();
this.txtSavedAmount = new System.Windows.Forms.TextBox();
this.btnCalculate = new System.Windows.Forms.Button();
this.btnReset = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lblDays
//
this.lblDays.AutoSize = true;
this.lblDays.Location = new System.Drawing.Point(130, 54);
this.lblDays.Name = "lblDays";
this.lblDays.Size = new System.Drawing.Size(84, 13);
this.lblDays.TabIndex = 0;
this.lblDays.Text = "Days on the trip:";
//
// lblAirfare
//
this.lblAirfare.AutoSize = true;
this.lblAirfare.Location = new System.Drawing.Point(135, 83);
this.lblAirfare.Name = "lblAirfare";
this.lblAirfare.Size = new System.Drawing.Size(79, 13);
this.lblAirfare.TabIndex = 1;
this.lblAirfare.Text = "Airfare Amount:";
//
// lblCar
//
this.lblCar.AutoSize = true;
this.lblCar.Location = new System.Drawing.Point(136, 110);
this.lblCar.Name = "lblCar";
this.lblCar.Size = new System.Drawing.Size(78, 13);
this.lblCar.TabIndex = 2;
this.lblCar.Text = "Car rental fees:";
//
// lblMiles
//
this.lblMiles.AutoSize = true;
this.lblMiles.Location = new System.Drawing.Point(148, 140);
this.lblMiles.Name = "lblMiles";
this.lblMiles.Size = new System.Drawing.Size(66, 13);
this.lblMiles.TabIndex = 3;
this.lblMiles.Text = "Miles driven:";
//
// lblParking
//
this.lblParking.AutoSize = true;
this.lblParking.Location = new System.Drawing.Point(145, 170);
this.lblParking.Name = "lblParking";
this.lblParking.Size = new System.Drawing.Size(69, 13);
this.lblParking.TabIndex = 4;
this.lblParking.Text = "Parking fees:";
//
// lblTaxi
//
this.lblTaxi.AutoSize = true;
this.lblTaxi.Location = new System.Drawing.Point(143, 199);
this.lblTaxi.Name = "lblTaxi";
this.lblTaxi.Size = new System.Drawing.Size(71, 13);
this.lblTaxi.TabIndex = 5;
this.lblTaxi.Text = "Taxi charges:";
//
// lblSeminar
//
this.lblSeminar.AutoSize = true;
this.lblSeminar.Location = new System.Drawing.Point(21, 225);
this.lblSeminar.Name = "lblSeminar";
this.lblSeminar.Size = new System.Drawing.Size(193, 13);
this.lblSeminar.TabIndex = 6;
this.lblSeminar.Text = "Conference or seminar registration fees:";
//
// lblLodging
//
this.lblLodging.AutoSize = true;
this.lblLodging.Location = new System.Drawing.Point(125, 256);
this.lblLodging.Name = "lblLodging";
this.lblLodging.Size = new System.Drawing.Size(89, 13);
this.lblLodging.TabIndex = 7;
this.lblLodging.Text = "Lodging charges:";
//
// txtDayTrip
//
this.txtDayTrip.Location = new System.Drawing.Point(220, 47);
this.txtDayTrip.Name = "txtDayTrip";
this.txtDayTrip.Size = new System.Drawing.Size(116, 20);
this.txtDayTrip.TabIndex = 8;
//
// txtAirfareAmount
//
this.txtAirfareAmount.Location = new System.Drawing.Point(220, 80);
this.txtAirfareAmount.Name = "txtAirfareAmount";
this.txtAirfareAmount.Size = new System.Drawing.Size(116, 20);
this.txtAirfareAmount.TabIndex = 9;
//
// txtCarRentalFees
//
this.txtCarRentalFees.Location = new System.Drawing.Point(220, 110);
this.txtCarRentalFees.Name = "txtCarRentalFees";
this.txtCarRentalFees.Size = new System.Drawing.Size(116, 20);
this.txtCarRentalFees.TabIndex = 10;
//
// txtMiles
//
this.txtMiles.Location = new System.Drawing.Point(220, 140);
this.txtMiles.Name = "txtMiles";
this.txtMiles.Size = new System.Drawing.Size(116, 20);
this.txtMiles.TabIndex = 11;
//
// txtParking
//
this.txtParking.Location = new System.Drawing.Point(220, 170);
this.txtParking.Name = "txtParking";
this.txtParking.Size = new System.Drawing.Size(116, 20);
this.txtParking.TabIndex = 12;
//
// txtTaxiCharge
//
this.txtTaxiCharge.Location = new System.Drawing.Point(220, 199);
this.txtTaxiCharge.Name = "txtTaxiCharge";
this.txtTaxiCharge.Size = new System.Drawing.Size(116, 20);
this.txtTaxiCharge.TabIndex = 13;
//
// txtConferenceFees
//
this.txtConferenceFees.Location = new System.Drawing.Point(220, 225);
this.txtConferenceFees.Name = "txtConferenceFees";
this.txtConferenceFees.Size = new System.Drawing.Size(116, 20);
this.txtConferenceFees.TabIndex = 14;
//
// txtLodgingFees
//
this.txtLodgingFees.Location = new System.Drawing.Point(220, 253);
this.txtLodgingFees.Name = "txtLodgingFees";
this.txtLodgingFees.Size = new System.Drawing.Size(116, 20);
this.txtLodgingFees.TabIndex = 15;
//
// lblExpense
//
this.lblExpense.AutoSize = true;
this.lblExpense.Location = new System.Drawing.Point(38, 301);
this.lblExpense.Name = "lblExpense";
this.lblExpense.Size = new System.Drawing.Size(231, 13);
this.lblExpense.TabIndex = 16;
this.lblExpense.Text = "Total expenses incurred by the businessperson:";
//
// lblAllowedExpense
//
this.lblAllowedExpense.AutoSize = true;
this.lblAllowedExpense.Location = new System.Drawing.Point(72, 328);
this.lblAllowedExpense.Name = "lblAllowedExpense";
this.lblAllowedExpense.Size = new System.Drawing.Size(197, 13);
this.lblAllowedExpense.TabIndex = 17;
this.lblAllowedExpense.Text = "The total allowable expenses for the trip:";
//
// label11
//
this.label11.AutoSize = true;
this.label11.Location = new System.Drawing.Point(12, 356);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(257, 13);
this.label11.TabIndex = 18;
this.label11.Text = "The excess that must be paid by the businessperson:";
//
// label12
//
this.label12.AutoSize = true;
this.label12.Location = new System.Drawing.Point(62, 383);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(207, 13);
this.label12.TabIndex = 19;
this.label12.Text = "The amount saved by the businessperson:";
//
// txtTotalExpenses
//
this.txtTotalExpenses.Location = new System.Drawing.Point(275, 298);
this.txtTotalExpenses.Name = "txtTotalExpenses";
this.txtTotalExpenses.ReadOnly = true;
this.txtTotalExpenses.Size = new System.Drawing.Size(111, 20);
this.txtTotalExpenses.TabIndex = 20;
//
// txtAllowedExpenses
//
this.txtAllowedExpenses.Location = new System.Drawing.Point(275, 328);
this.txtAllowedExpenses.Name = "txtAllowedExpenses";
this.txtAllowedExpenses.ReadOnly = true;
this.txtAllowedExpenses.Size = new System.Drawing.Size(111, 20);
this.txtAllowedExpenses.TabIndex = 21;
//
// txtExcessAmount
//
this.txtExcessAmount.Location = new System.Drawing.Point(275, 356);
this.txtExcessAmount.Name = "txtExcessAmount";
this.txtExcessAmount.ReadOnly = true;
this.txtExcessAmount.Size = new System.Drawing.Size(111, 20);
this.txtExcessAmount.TabIndex = 22;
//
// txtSavedAmount
//
this.txtSavedAmount.Location = new System.Drawing.Point(275, 383);
this.txtSavedAmount.Name = "txtSavedAmount";
this.txtSavedAmount.ReadOnly = true;
this.txtSavedAmount.Size = new System.Drawing.Size(111, 20);
this.txtSavedAmount.TabIndex = 23;
//
// btnCalculate
//
this.btnCalculate.Location = new System.Drawing.Point(85, 440);
this.btnCalculate.Name = "btnCalculate";
this.btnCalculate.Size = new System.Drawing.Size(129, 33);
this.btnCalculate.TabIndex = 24;
this.btnCalculate.Text = "Calculate";
this.btnCalculate.UseVisualStyleBackColor = true;
this.btnCalculate.Click += new System.EventHandler(this.btnCalculate_Click);
//
// btnReset
//
this.btnReset.Location = new System.Drawing.Point(257, 440);
this.btnReset.Name = "btnReset";
this.btnReset.Size = new System.Drawing.Size(129, 33);
this.btnReset.TabIndex = 25;
this.btnReset.Text = "Reset";
this.btnReset.UseVisualStyleBackColor = true;
this.btnReset.Click += new System.EventHandler(this.btnReset_Click);
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(421, 440);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(129, 33);
this.btnExit.TabIndex = 26;
this.btnExit.Text = "Exit";
this.btnExit.UseVisualStyleBackColor = true;
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// ExpenseForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 507);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnReset);
this.Controls.Add(this.btnCalculate);
this.Controls.Add(this.txtSavedAmount);
this.Controls.Add(this.txtExcessAmount);
this.Controls.Add(this.txtAllowedExpenses);
this.Controls.Add(this.txtTotalExpenses);
this.Controls.Add(this.label12);
this.Controls.Add(this.label11);
this.Controls.Add(this.lblAllowedExpense);
this.Controls.Add(this.lblExpense);
this.Controls.Add(this.txtLodgingFees);
this.Controls.Add(this.txtConferenceFees);
this.Controls.Add(this.txtTaxiCharge);
this.Controls.Add(this.txtParking);
this.Controls.Add(this.txtMiles);
this.Controls.Add(this.txtCarRentalFees);
this.Controls.Add(this.txtAirfareAmount);
this.Controls.Add(this.txtDayTrip);
this.Controls.Add(this.lblLodging);
this.Controls.Add(this.lblSeminar);
this.Controls.Add(this.lblTaxi);
this.Controls.Add(this.lblParking);
this.Controls.Add(this.lblMiles);
this.Controls.Add(this.lblCar);
this.Controls.Add(this.lblAirfare);
this.Controls.Add(this.lblDays);
this.Name = "ExpenseForm";
this.Text = "Travel Expense Calculator";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label lblDays;
private System.Windows.Forms.Label lblAirfare;
private System.Windows.Forms.Label lblCar;
private System.Windows.Forms.Label lblMiles;
private System.Windows.Forms.Label lblParking;
private System.Windows.Forms.Label lblTaxi;
private System.Windows.Forms.Label lblSeminar;
private System.Windows.Forms.Label lblLodging;
private System.Windows.Forms.TextBox txtDayTrip;
private System.Windows.Forms.TextBox txtAirfareAmount;
private System.Windows.Forms.TextBox txtCarRentalFees;
private System.Windows.Forms.TextBox txtMiles;
private System.Windows.Forms.TextBox txtParking;
private System.Windows.Forms.TextBox txtTaxiCharge;
private System.Windows.Forms.TextBox txtConferenceFees;
private System.Windows.Forms.TextBox txtLodgingFees;
private System.Windows.Forms.Label lblExpense;
private System.Windows.Forms.Label lblAllowedExpense;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.TextBox txtTotalExpenses;
private System.Windows.Forms.TextBox txtAllowedExpenses;
private System.Windows.Forms.TextBox txtExcessAmount;
private System.Windows.Forms.TextBox txtSavedAmount;
private System.Windows.Forms.Button btnCalculate;
private System.Windows.Forms.Button btnReset;
private System.Windows.Forms.Button btnExit;
}
}
output: