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

4. Travel Expenses Create a GUI application that calculates and displays the tot

ID: 3837451 • Letter: 4

Question

4. Travel Expenses 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: 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 day Lodging charges up to $95.00 per mile driven If a private vehicle is used, $0.27 per The application should calculate and display the following: Total expenses incurred by the businessperson The total allowable expenses for the trip if any that must by the businessperson, The amount saved by the businessperson if the expenses were under the total allowed

Explanation / Answer

Please check with the following code it works definetly :

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.*;

/**
*
* @author Dhanesh
*/
public class ExpensesSpent extends JFrame {

private final int WIDTH = 500;
private final int HEIGHT = 500;
JPanel panel = new JPanel();
private JLabel numberOfDaysLabel;
private JLabel amountAirfareLabel;
private JLabel amontRentalFeeLabel;
private JLabel numberMilesLabel;
private JLabel parkingFeeLabel;
private JLabel taxiFeeLabel;
private JLabel seminarFeeLabel;
private JLabel lodgingFeeLabel;
private JTextField daysField;
private JTextField amountAirfareField;
private JTextField rentalFeeField;
private JTextField milesDrivenField;
private JTextField parkingFeeField;
private JTextField taxiFeeField;
private JTextField smeinarFeeField;
private JTextField lodgingFeeField;
private JButton calculateButton;

public ExpensesSpent() {
setTitle("Travel ExpensesSpent");
setSize(WIDTH, HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildPanel();
add(panel);
setVisible(true);

}

private void buildPanel() {

numberOfDaysLabel = new JLabel("Number of days on the trip: ");
daysField = new JTextField(10);

amountAirfareLabel = new JLabel("Amount of airfare: ");
amountAirfareField = new JTextField(10);

amontRentalFeeLabel = new JLabel("Amount of car rental fee: ");
rentalFeeField = new JTextField(10);

numberMilesLabel = new JLabel("Number of miles driven: ");
milesDrivenField = new JTextField(10);

parkingFeeLabel = new JLabel("Amount of parking fees: ");
parkingFeeField = new JTextField(10);

taxiFeeLabel = new JLabel("Taxi charges: ");
taxiFeeField = new JTextField(10);

seminarFeeLabel = new JLabel("Conference or seminar registration fees: ");
smeinarFeeField = new JTextField(10);

lodgingFeeLabel = new JLabel("Lodging charges, per night");
lodgingFeeField = new JTextField(10);

calculateButton = new JButton("Calculate");
calculateButton.addActionListener(new buttonListener());
panel = new JPanel(new GridLayout(9, 2, 5, 10));

panel.add(numberOfDaysLabel);
panel.add(daysField);
panel.add(amountAirfareLabel);
panel.add(amountAirfareField);
panel.add(amontRentalFeeLabel);
panel.add(rentalFeeField);
panel.add(numberMilesLabel);
panel.add(milesDrivenField);
panel.add(parkingFeeLabel);
panel.add(parkingFeeField);
panel.add(taxiFeeLabel);
panel.add(taxiFeeField);
panel.add(seminarFeeLabel);
panel.add(smeinarFeeField);
panel.add(lodgingFeeLabel);
panel.add(lodgingFeeField);
panel.add(calculateButton);

}

public class buttonListener implements ActionListener {

public void actionPerformed(ActionEvent e) {
String stringDay, stringAirfare, stringCarRental, stringMilesDriven, stringParkingFee, stringTaxiCharges, stringSeminarFee, stringLodgingFee;
double totalAllowed, totalOwe, totalSaved, totalExpenses, numberDays, AirFare, CarRental, MilesDriven, ParkingFee, TaxiCharges, seminarFee, lodgingFee;
final double dayMeal = 37.00;
final double parkingFee = 10.00;
final double taxiFee = 20.00;
final double lodgingCharge = 95.00;
final double rentCar = 0.27;
double totalMilesDriven;

stringDay = daysField.getText();
numberDays = Double.parseDouble(stringDay);

stringAirfare = amountAirfareField.getText();
AirFare = Double.parseDouble(stringAirfare);

stringCarRental = rentalFeeField.getText();
CarRental = Double.parseDouble(stringCarRental);

stringMilesDriven = milesDrivenField.getText();
MilesDriven = Double.parseDouble(stringMilesDriven);

stringParkingFee = parkingFeeField.getText();
ParkingFee = Double.parseDouble(stringParkingFee);

stringTaxiCharges = taxiFeeField.getText();
TaxiCharges = Double.parseDouble(stringTaxiCharges);

stringSeminarFee = smeinarFeeField.getText();
seminarFee = Double.parseDouble(stringSeminarFee);

stringLodgingFee = lodgingFeeField.getText();
lodgingFee = Double.parseDouble(stringLodgingFee);

totalMilesDriven = MilesDriven * rentCar;
totalExpenses = AirFare * CarRental * MilesDriven * ParkingFee * TaxiCharges * seminarFee * lodgingFee;
totalAllowed = numberDays * dayMeal * parkingFee * taxiFee * lodgingCharge * rentCar * totalMilesDriven;

if (totalExpenses > totalAllowed) {
totalOwe = totalExpenses - totalAllowed;
} else {
totalOwe = 0;
}

if (totalAllowed > totalExpenses) {
totalSaved = totalAllowed - totalExpenses;
} else {
totalSaved = 0;
}


System.out.println("The total ExpensesSpent for the trip are " + totalExpenses
+ " The total allowed to spend is " + totalAllowed + " The total you owe is "
+ totalOwe + " Total saved is " + totalSaved);

}
}
}

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