In: Computer Science
In C#
Create a GUI application that calculates and displays the total travel expenses of a business person on a trip. Here is the information that the user must provide:
The company reimburses travel expenses according to the following policy:
The application should calculate and display the following:
Note: Done accordingly. Please comment for any problem. Please Uprate. Thanks
Download solution:
https://drive.google.com/file/d/1f-hDbegoeClXzr7Kwit4gJee4TP3qTUH/view?usp=sharing
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TravelExpenceCalculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCalculate_Click(object sender, EventArgs e)
{
//declaring variables
int numberOfDays;
double amountOfAirfare = 0, amountOfCarRental = 0,
numberOfMilesDriven = 0, amountOfParkingFees = 0,
amountOfTaxiCharges = 0, conferenceFees = 0, lodgingCharges;
double totalExpense, totalReimbursement, extra=0, saved=0;
//checking if number of days are given
if (tbNumdays.Text.Equals(""))
{
MessageBox.Show("Please give number of days.");
}
//checking if lodging charges are given
else if (tbLodging.Text.Equals(""))
{
MessageBox.Show("Please give logding charges.");
}
else
{
try
{
//parsing input
numberOfDays = Int32.Parse(tbNumdays.Text);
amountOfCarRental=getValue(tbCarRental);
amountOfAirfare = getValue(tbAirfare);
numberOfMilesDriven = getValue(tbNumMiles);
amountOfParkingFees = getValue(tbParkingFees);
amountOfTaxiCharges = getValue(tbTaxiCharges);
conferenceFees = getValue(tbConferenceCharge);
lodgingCharges=double.Parse(tbLodging.Text);
//calculating total expenses
totalExpense=numberOfDays*(lodgingCharges+amountOfCarRental+amountOfParkingFees+amountOfTaxiCharges)+amountOfAirfare+conferenceFees;
//calculating total allowable
totalReimbursement = numberOfDays * (37 + 10 + 20 + 95) + (0.27 *
numberOfMilesDriven);
//checking whether expense is more than allowable
if (totalExpense > totalReimbursement)
{
extra = totalExpense - totalReimbursement; //setting extra money to
pay
}
else
{
saved = totalReimbursement - totalExpense; //setting money
saved
}
//setting textbox values
tbExcessMoney.Text = extra.ToString();
tbTotalExpense.Text = totalExpense.ToString();
tbAmountSaved.Text = saved.ToString();
tbAllowable.Text = totalReimbursement.ToString();
}catch(Exception exp){
//error message for non double input
MessageBox.Show("Please give proper input." + exp.Message);
}
}
}
private double getValue(TextBox tb)
{
//setting value based on input
//if no input is given then 0 is set
if (tb.Text.Equals(""))
{
return 0;
}
else
{
return double.Parse(tb.Text);
}
}
}
}
Output: