Question: Travel Expenses (Java) Create a GUI application that calculates and displays the total expenses of a business person on a trip. Here is the information
Travel Expenses (Java)
Create a GUI application that calculates and displays the total 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 feeds, 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 fees, up to $20.00 per day
Lodging charges, up to $95.00 per day
If a private vehicle is used, $0.27 per mile
The application should calculate and display the following:
Total expenses incurred by the business person
The total allowable expenses for the trip
The excess that must be paid by the business person, if any
The amount saved by the business person if the expenses are under the total allowed
TravelExpenses.java
import javax.swing.*; import java.awt.event.*;
public class travelexpenses extends JFrame { private final double MEALS = 37.00; private final double PARKING = 10.00; private final double TAXI = 20.00; private final double LODGING = 95.00; private final double OWNCAR = .27; private final int WINDOW_WIDTH = 500; private final int WINDOW_HEIGHT = 500; private JPanel panel; private JButton button; private JLabel days; private JLabel airfare; private JLabel rentalcar; private JLabel privatecar; private JLabel parkfees; private JLabel taxicharges; private JLabel semcharges; private JLabel hotelcharges; private JTextField days1; private JTextField airfare1; private JTextField rentalcar1; private JTextField privatecar1; private JTextField parkfees1; private JTextField taxicharges1; private JTextField semcharges1; private JTextField hotelcharges1;
public travelexpenses() { setTitle("Travel Expenses Calculator"); setSize(WINDOW_WIDTH, WINDOW_HEIGHT); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); buildPanel(); add(panel); setVisible(true); }
private void buildPanel() { days = new JLabel("How many days are you staying?"); days1 = new JTextField(3); airfare = new JLabel("How much did you spend on airfare?"); airfare1 = new JTextField(10); rentalcar = new JLabel("How much did you spend on a car rental? "); rentalcar1 = new JTextField(10); privatecar = new JLabel("How much mileage was used on your car?"); privatecar1 = new JTextField(10); parkfees = new JLabel("How much in parking fees did you pay?"); parkfees1 = new JTextField(10); taxicharges = new JLabel("How much did you spend on taxi's?"); taxicharges1 = new JTextField(10); semcharges = new JLabel("How much did you spend on seminars?"); semcharges1 = new JTextField(10); hotelcharges = new JLabel("How much did you spend on the hotel?"); hotelcharges1 = new JTextField(10); button = new JButton("Calculate."); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int day; double air; double rentacar; double owncar; double parking; double taxi; double seminar; double hotel; double total; double adjusted; double newtotal; double moneysaved; double moneyowed;
day = Integer.parseInt(days1.getText()); air = Double.parseDouble(airfare1.getText()); rentacar = Double.parseDouble(rentalcar1.getText()); owncar = Double.parseDouble(privatecar1.getText()); parking = Double.parseDouble(parkfees1.getText()); taxi = Double.parseDouble(taxicharges1.getText()); seminar = Double.parseDouble(semcharges1.getText()); hotel = Double.parseDouble(hotelcharges1.getText()); total = air + rentacar + owncar + parking + taxi + seminar + hotel; adjusted = day*MEALS + day*PARKING + day*TAXI + day*LODGING + owncar*OWNCAR; newtotal = total - adjusted; if(total > newtotal) moneyowed = total - newtotal; if(total < newtotal) moneysaved = } } ); panel = new JPanel();
panel.add(days); panel.add(days1); panel.add(airfare); panel.add(airfare1); panel.add(rentalcar); panel.add(rentalcar1); panel.add(privatecar); panel.add(privatecar1); panel.add(parkfees); panel.add(parkfees1); panel.add(taxicharges); panel.add(taxicharges1); panel.add(semcharges); panel.add(semcharges1); panel.add(hotelcharges); panel.add(hotelcharges1); panel.add(button); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
