In: Computer Science
Design and implement a Java program to create a GUI application that for calculating an employee’s travel expenses and reimbursement. The user will enter the following data:
∙ Number of days on the trip
∙ Amount of the airfare, if any
∙ Amount of car rental fees, if any
∙ Number of miles driven, if a private vehicle is used
∙ Amount of parking fees, if any
∙ Amount of taxi charges, if any
∙ Conference or seminar registration fees, if any
∙ Lodging charges, per night
Once all expanses are entered the program should then calculate what the employee’s reimbursement will be based on the following guidelines:
∙ $17 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
Once calculated your program should display the following information:
∙ 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
The layout and formatting of your GUI interface should be creative, attractive and easy to use.











Source Code:
package travelexpenses;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class TravExp extends JFrame
{
private JPanel traInfoPan;
private JPanel butPan;
private JLabel daysLabel;
private JLabel airfairLabel;
private JLabel carRentLabel;
private JLabel milesLabel;
private JLabel parkingLabel;
private JLabel taxiLabel;
private JLabel confLabel;
private JLabel lodgeLabel;
private JTextField daysTextField;
private JTextField airfairTextField;
private JTextField carRentTextField;
private JTextField milTextField;
private JTextField paTextField;
private JTextField txTextField;
private JTextField confTextField;
private JTextField lodgeTextField;
private JButton reset_Button;
private JButton calculate_Button;
private double mealAmt = 37.00;
private double parkfeesReimb = 10.00;
private double taxichargeReimb = 20.00;
private double lodgchargeReimb = 95.00;
private double privVehReimb = 0.27;
public TravExp( )
{
super("TRAVEL EXPENSES");
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
build_Trav_Info();
build_But_Pan();
add(traInfoPan, BorderLayout.CENTER);
add(butPan, BorderLayout.SOUTH);
pack();
setVisible(true);
}
private void build_Trav_Info()
{
daysLabel = new JLabel("Number of days on trip: ");
airfairLabel = new JLabel("Amount of airfair: ");
carRentLabel = new JLabel("Amount of car rental fees: ");
milesLabel = new JLabel("Number of Miles driven: ");
parkingLabel = new JLabel("Amount of Parking fees: ");
taxiLabel = new JLabel("Amount of Taxi charges: ");
confLabel = new JLabel("Conference or Seminar registration fees:
");
lodgeLabel = new JLabel("Lodging charges per night: ");
daysTextField = new JTextField(3);
airfairTextField = new JTextField(8);
carRentTextField = new JTextField(8);
milTextField = new JTextField(4);
paTextField = new JTextField(6);
txTextField = new JTextField(6);
confTextField = new JTextField(8);
lodgeTextField = new JTextField(6);
traInfoPan = new JPanel();
traInfoPan.setLayout(new GridLayout(10, 2));
traInfoPan.add(daysLabel);
traInfoPan.add(daysTextField);
traInfoPan.add(airfairLabel);
traInfoPan.add(airfairTextField);
traInfoPan.add(carRentLabel);
traInfoPan.add(carRentTextField);
traInfoPan.add(milesLabel);
traInfoPan.add(milTextField);
traInfoPan.add(parkingLabel);
traInfoPan.add(paTextField);
traInfoPan.add(taxiLabel);
traInfoPan.add(txTextField);
traInfoPan.add(confLabel);
traInfoPan.add(confTextField);
traInfoPan.add(lodgeLabel);
traInfoPan.add(lodgeTextField);
traInfoPan.setBorder(BorderFactory.createEmptyBorder(10, 10, 1,
10));
}
private void build_But_Pan()
{
calculate_Button = new JButton("CALCULATE");
calculate_Button.addActionListener(new
calculate_ButtonListener());
reset_Button = new JButton("RESET");
butPan = new JPanel();
butPan.setLayout(new BorderLayout(5, 5));
butPan.add(reset_Button, BorderLayout.WEST);
butPan.add(calculate_Button, BorderLayout.CENTER);
butPan.setBorder(BorderFactory.createEmptyBorder(1, 10, 10,
10));
}
private class calculate_ButtonListener implements
ActionListener
{
String inp;
int dy;
double ar;
double carrent;
double mls;
double park;
double tx;
double conf;
double lodg;
double mealAmt;
public void actionPerformed(ActionEvent e)
{
double actExp;
double milesExp;
double allowExp;
double exAir;
double exCarRen;
double exCarPark;
double exTaxi;
double exLodg;
double exAmtTot;
double amtSav=0;
double paidBackAmt=0;
DecimalFormat dol = new DecimalFormat("$#,##0.00");
dy = Integer.parseInt(daysTextField.getText());
ar = Double.parseDouble(airfairTextField.getText());
carrent = Double.parseDouble(carRentTextField.getText());
mls = Double.parseDouble(milTextField.getText());
park = Double.parseDouble(paTextField.getText());
tx = Double.parseDouble(txTextField.getText());
conf = Double.parseDouble(confTextField.getText());
lodg = Double.parseDouble(lodgeTextField.getText());
milesExp = mls * privVehReimb;
actExp = (carrent + park + tx + lodg +mealAmt)
*dy+ar+milesExp+ conf ;
allowExp=(mealAmt+parkfeesReimb+taxichargeReimb+lodgchargeReimb)*dy+milesExp+ar+conf;
if(actExp>allowExp)
paidBackAmt=actExp-allowExp;
else
amtSav=allowExp-actExp;
if(paidBackAmt>0)
JOptionPane.showMessageDialog(null, "Total expenses: "
+ dol.format(actExp) +"\n" +"Total allowable expenses: "
+ dol.format(allowExp)+"\n" +"\n" + "Amount to be paid back:
"
+dol.format(paidBackAmt));
else if(amtSav>0)
JOptionPane.showMessageDialog(null, "Total expenses: " +
dol.format(actExp)
+"\n" +" Total allowable expenses: " + dol.format(allowExp)+"\n"
+
"\n" + "Amount Saved: "+dol.format(amtSav));
else
JOptionPane.showMessageDialog(null, "Total expenses: " +
dol.format(actExp)
+"\n" +"Allowable expenses: " + dol.format(allowExp)+"\n" );
}
}
private class reset_ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
daysTextField.setText("");
airfairTextField.setText("");
carRentTextField.setText("");
milTextField.setText("");
paTextField.setText("");
txTextField.setText("");
confTextField.setText("");
lodgeTextField.setText("");
}
}
public static void main(String[] args)
{
new TravExp();
}
}