In: Computer Science
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
Here is the code and please let me know if any errors occurs.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class TravelExpenses extends JFrame
013
{
private JPanel travelInfoPanel;
private JPanel buttonPanel;
private JLabel numDaysOnTripLabel;
private JLabel amountAirfairLabel;
private JLabel amountCarRentalLabel;
private JLabel milesDrivenLabel;
private JLabel parkingFeesLabel;
private JLabel taxiFeesLabel;
private JLabel confRegLabel;
private JLabel lodgingChargesPerNightLabel;
private JTextField numDaysOnTripTextField;
private JTextField amountAirfairTextField;
private JTextField amountCarRentalTextField;
private JTextField milesDrivenTextField;
private JTextField parkingFeesTextField;
private JTextField taxiFeesTextField;
private JTextField confRegTextField;
private JTextField lodgingChargesPerNightTextField;
private JButton resetButton;
private JButton calcButton;
private double mealsAmount = 37.00;
private double parkingFeesReimbursed = 10.00;
private double taxiChargesReimbursed = 20.00;
private double lodgingChargesReimbursed = 95.00;
private double prVechiclePerMileReimbursed = 0.27;
public TravelExpenses()
{
super("Travel Expenses");
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
buildTravelInfoPanel();
buildButtonPanel();
add(travelInfoPanel, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
pack();
080
setVisible(true);
081
}
private void buildTravelInfoPanel()
{
numDaysOnTripLabel = new JLabel("Number of days on trip: ");
amountAirfairLabel = new JLabel("Amount of airfair: ");
amountCarRentalLabel = new JLabel("Amount of car rental: ");
milesDrivenLabel = new JLabel("Miles driven: ");
parkingFeesLabel = new JLabel("Parking Fees: ");
taxiFeesLabel = new JLabel("Taxi fees: ");
confRegLabel = new JLabel("Conference registration: ");
lodgingChargesPerNightLabel = new JLabel("Lodging charges per night: ");
numDaysOnTripTextField = new JTextField(3);
amountAirfairTextField = new JTextField(8);
amountCarRentalTextField = new JTextField(8);
milesDrivenTextField = new JTextField(4);
parkingFeesTextField = new JTextField(6);
taxiFeesTextField = new JTextField(6);
confRegTextField = new JTextField(8);
lodgingChargesPerNightTextField = new JTextField(6);
travelInfoPanel = new JPanel();
travelInfoPanel.setLayout(new GridLayout(10, 2));
travelInfoPanel.add(numDaysOnTripLabel);
travelInfoPanel.add(numDaysOnTripTextField);
travelInfoPanel.add(amountAirfairLabel);
travelInfoPanel.add(amountAirfairTextField);
travelInfoPanel.add(amountCarRentalLabel);
travelInfoPanel.add(amountCarRentalTextField);
travelInfoPanel.add(milesDrivenLabel);
travelInfoPanel.add(milesDrivenTextField);
travelInfoPanel.add(parkingFeesLabel);
travelInfoPanel.add(parkingFeesTextField);
travelInfoPanel.add(taxiFeesLabel);
travelInfoPanel.add(taxiFeesTextField);
travelInfoPanel.add(confRegLabel);
travelInfoPanel.add(confRegTextField);
travelInfoPanel.add(lodgingChargesPerNightLabel);
travelInfoPanel.add(lodgingChargesPerNightTextField);
travelInfoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 1, 10));
private void buildButtonPanel()
calcButton = new JButton("Calculate");
calcButton.addActionListener(new CalcButtonListener());
resetButton = new JButton("Reset");
buttonPanel = new JPanel();
buttonPanel.setLayout(new BorderLayout(5, 5));
buttonPanel.add(resetButton, BorderLayout.WEST);
buttonPanel.add(calcButton, BorderLayout.CENTER);
buttonPanel.setBorder(BorderFactory.createEmptyBorder(1, 10, 10, 10));
}
private class CalcButtonListener implements ActionListener
{
String input;
int days;
double air;
double carRental;
double miles;
double parking;
double taxi;
double confReg;
double lodging;
double mealsAmount;
public void actionPerformed(ActionEvent e)
{
double actualExpenses;
double milesExpenses;
double allowableExpenses;
double excessAir;
double excessCarRental;
double excessParking;
double excessTaxi;
double excessLodging;
double excessAmountTotal;
double amountSaved;
double paidBackAmount;
DecimalFormat dollar = new DecimalFormat("$#,##0.00");
}
private void getData()
{
days = Integer.parseInt(numDaysOnTripTextField.getText());
air = Double.parseDouble(amountAirfairTextField.getText());
carRental = Double.parseDouble(amountCarRentalTextField.getText());
miles = Double.parseDouble(milesDrivenTextField.getText());
parking = Double.parseDouble(parkingFeesTextField.getText());
taxi = Double.parseDouble(taxiFeesTextField.getText());
confReg = Double.parseDouble(confRegTextField.getText());
lodging = Double.parseDouble(lodgingChargesPerNightTextField.getText());
}
private void determineActualExpenses(double actualExpenses, double milesExpenses)
{
actualExpenses = air + carRental + parking + taxi + confReg + lodging;actualExpenses = actualExpenses + milesExpenses;
JOptionPane.showMessageDialog(null, "Total expenses: " + "\n" +"Allowable expenses: " + "\n" +"\n" + "Amount to be paid back: ");
}
private class ResetButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
numDaysOnTripTextField.setText("");
amountAirfairTextField.setText("");
amountCarRentalTextField.setText("");
milesDrivenTextField.setText("");
parkingFeesTextField.setText("");
taxiFeesTextField.setText("");
confRegTextField.setText("");
lodgingChargesPerNightTextField.setText("");
}
}
}
public static void main(String[] args)
{
new TravelExpenses();
}
THANK YOU!! PLEASE VOTE