Question

creat a GUI APPLICATION that calculates and displays the total travel expenses of...continues

creat a GUI APPLICATION that calculates and displays the total travel expenses of a business person on a tripmhere is the information that a user provide:-number ofdays on the trip,amount of airfare,amount of car rental fees,if any,number of miles driven,if the private vehicle was used,amount of parking fees,amount of taxicharges,conference or seminar fees,lodging charges per night.The company reimburses trevel expenses according to following policy:$37 per day for meals,parking fees,upto $10 per day,taxi charges up to$ 20.00per week.lodging charges up to $95.00 per day,if a private vehicle is used@.27permile driven,the application should calculateand display the followingtotal expenses incurred by the business person,the total allowable expense for the trip,the expense that paid by the business person,the amount saved by the businessperson if the expenses under total allowed
0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

Dear,

Here is the code

//Header File sectionimport java.awt.*;
import java.awt.event.*;
import javax.swing.*;import javax.swing.JOptionPane;import java.text.DecimalFormat;
//Class name declaration
public class TravelExpenses extends JFrame
{private JPanel travelInfoPanel;private JPanel buttonPanel;// Labelsprivate JLabel numDaysOnTripLabel;private JLabel amountAirfairLabel;private JLabel amountCarRentalLabel;private JLabel milesDrivenLabel;private JLabel parkingFeesLabel;private JLabel taxiFeesLabel;private JLabel confRegLabel;private JLabel lodgingChargesPerNightLabel; // Text Fieldsprivate JTextField numDaysOnTripTextField;private JTextField amountAirfairTextField;private JTextField amountCarRentalTextField;private JTextField milesDrivenTextField;private JTextField parkingFeesTextField;private JTextField taxiFeesTextField;private JTextField confRegTextField;private JTextField lodgingChargesPerNightTextField;// Buttonsprivate JButton resetButton;private JButton calcButton;// Meals amount reimbursed by company per day.
private double mealsAmount = 37.00;
// Parking Fees amount reimbursed by company per day.
private double parkingFeesReimbursed = 10.00;
// Taxi Charges amount reimbursed by company per day.
private double taxiChargesReimbursed = 20.00;
// Lodging Charges amount reimbursed by company per day.
private double lodgingChargesReimbursed = 95.00;
// Private Vehicle per miles reimbursment rate.
private double prVechiclePerMileReimbursed = 0.27;
// Constructor
public TravelExpenses( )
{
//set the title.
super("TRAVEL EXPENSES");
// Set the main window
setLocationRelativeTo(null);
// Specify an action for the close button.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create a BorderLayout manager for the content pane.
setLayout(new BorderLayout());
// Build the TravelInfo and Buttons panels
buildTravelInfoPanel();
buildButtonPanel();
// Add the panels to the frame's content pane
add(travelInfoPanel, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
// Pack the contents of the window and display it.
pack();
setVisible(true);
}
// The buildTravelInfoPanel method adds the labels
//and text fiels to the TravelInfo panel.
private void buildTravelInfoPanel()
{
// Create the labels for TravelInfo fields
numDaysOnTripLabel = new JLabel("Number of days on trip: ");
amountAirfairLabel = new JLabel("Amount of airfair: ");
amountCarRentalLabel = new JLabel("Amount of car rental fees: ");
milesDrivenLabel = new JLabel("Number of Miles driven: ");
parkingFeesLabel = new JLabel("Amount of Parking fees: ");
taxiFeesLabel = new JLabel("Amount of Tax charges: ");
confRegLabel = new JLabel("Conference or Seminar registration fees: ");
lodgingChargesPerNightLabel = new JLabel("Lodging charges per night: ");
// Create the text boxes for TravelInfo user input
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);
// Create a panel to hold labels and text fields.
travelInfoPanel = new JPanel();
// Create GridLayout manager
travelInfoPanel.setLayout(new GridLayout(10, 2));
// Add the labels and text fields to this panel.
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);
// Add an empty border around the panel for spacing.
travelInfoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 1, 10));
}
/*** The buildButtonPanel method creates and adds the Reset and Calculate
* buttons to the TravelExpense panel as its own panel.
*/
private void buildButtonPanel()
{
// Create the calcButton.
calcButton = new JButton("CALCULATE");
// Register an event listener
calcButton.addActionListener(new CalcButtonListener());
//Create the resetButton.
resetButton = new JButton("RESET");
// Create the Buttons panels.
buttonPanel = new JPanel();
// Create BorderLayout manager.
buttonPanel.setLayout(new BorderLayout(5, 5));
// Add the two buttons to the buttonPanel.
buttonPanel.add(resetButton, BorderLayout.WEST);
buttonPanel.add(calcButton, BorderLayout.CENTER);
// Add an empty border around the panel for spacing.
buttonPanel.setBorder(BorderFactory.createEmptyBorder(1, 10, 10, 10));
}
/*** Private inner class that handles the event when the user clicks
* the Calculate button .
*/
private class CalcButtonListener implements ActionListener
{
// Declare variables
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)
{
//Declare variables
double actualExpenses;
double milesExpenses;
double allowableExpenses;
double excessAir;
double excessCarRental;
double excessParking;
double excessTaxi;
double excessLodging;
double excessAmountTotal;
double amountSaved=0;
double paidBackAmount=0;
// Create a DecimalFormat object to format the totals as dollar amounts.
DecimalFormat dollar = new DecimalFormat("$#,##0.00");
// Get Input Data the user entered in the text fields.
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());
// Determine actualExpenses method.
milesExpenses = miles * prVechiclePerMileReimbursed;
actualExpenses = (carRental + parking + taxi + lodging +mealsAmount)
*days+air+milesExpenses+ confReg ;
// Calculate the allowableExpenses.
allowableExpenses=(mealsAmount+parkingFeesReimbursed+taxiChargesReimbursed+lodgingChargesReimbursed)*days+milesExpenses+air+confReg;
// Calculate the paidBackAmount.
if(actualExpenses>allowableExpenses)
paidBackAmount=actualExpenses-allowableExpenses;
else
amountSaved=allowableExpenses-actualExpenses;
// Display the Totals message box.
if(paidBackAmount>0)
JOptionPane.showMessageDialog(null, "Total expenses: "
+ dollar.format(actualExpenses)+"n" +"Allowableexpenses: "
+ dollar.format(allowableExpenses)+"n" +"n" + "Amount to be paidback: "
+dollar.format(paidBackAmount));
else if(amountSaved>0)
JOptionPane.showMessageDialog(null, "Total expenses: " + dollar.format(actualExpenses)
+"n" +"Allowable expenses: " + dollar.format(allowableExpenses)+"n" +
"n" + "Amount Saved: "+dollar.format(amountSaved));
else
JOptionPane.showMessageDialog(null, "Total expenses: " + dollar.format(actualExpenses)
+"n" +"Allowable expenses: " + dollar.format(allowableExpenses)+"n" );
}
}
/*** Private inner class that handles the event when the user clicks
* the RESET button .
*/
private class ResetButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e){}}// The main method
public static void main(String[] args)
{
new TravelExpenses();}}Output:uploaded imageHope this will help you..
answered by: aaron
Add a comment
Know the answer?
Add Answer to:
creat a GUI APPLICATION that calculates and displays the total travel expenses of...continues
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Travel Expenses Create a GUI in C# Visual Studios application that calculates and displays the total...

    Travel Expenses Create a GUI in C# Visual Studios 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...

  • Please help, need to code for this business assignment using c++. Business Expense Reimbursements Calculator Probl...

    Please help, need to code for this business assignment using c++. Business Expense Reimbursements Calculator Problem statement: Business trip is part of the enterprise culture. Suppose a businessperson just completed a business trip for your company. Now, you are tasked to write a program that calculates and displays the total travel expenses, allowable expenses for the trip, and the excess that must be paid by the businessperson, if any The program should prompt the user for the following . The...

  • JAVA Hello I am trying to add a menu to my Java code if someone can...

    JAVA Hello I am trying to add a menu to my Java code if someone can help me I would really appreacite it thank you. I found a java menu code but I dont know how to incorporate it to my code this is the java menu code that i found. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; public class MenuExp extends JFrame { public MenuExp() { setTitle("Menu Example");...

  • Create an application that calculates the total cost of a hospital stay. The application should accept...

    Create an application that calculates the total cost of a hospital stay. The application should accept the following input: the number of days spent in the hospital (as an integer), the amount of medication charges, the amount of surgical charges, the amount of lab fees, and the amount of physical rehabilitation charges. The hospital charges $350 per day. Create the following functions. A. CalcStayCharges- Calculates and returns the base charges for the hospital stay. This is computed as $350 times...

  • total itemized deductions are given - $12,300 using the information, fill out SCHEDULE A 2018 FORM...

    total itemized deductions are given - $12,300 using the information, fill out SCHEDULE A 2018 FORM 1:9-72 George Large (SSN 000-11-1111) and his wife Marge Large (SSN 000-22-2222) live at 2000 Lakeview Drive, Cleveland, OH 49001 and want you to prepare their 2017 income tax return based on the information below: George Large worked as a salesman for Toyboat, Inc. He received a salary of $80,000 ($8,500 of federal income taxes withheld and $1,800 of state income taxes withheld) plus...

  • please answer #2 The Stratton Township Park The Stratton Township Park is located on a piece...

    please answer #2 The Stratton Township Park The Stratton Township Park is located on a piece of property that contains two golf courses, a swimming pool, and 800 acres of woods and open spaces. Three years ago, the Stratton Parks Department (Stratton) carved out miles of trails to allow visitors to hike the property and enjoy nature. To make that experience more enjoyable for visitors and available to school groups, Stratton decided to offer guided tours that have proven popular....

  • please answer #5 The Stratton Township Park The Stratton Township Park is located on a piece...

    please answer #5 The Stratton Township Park The Stratton Township Park is located on a piece of property that contains two golf courses, a swimming pool, and 800 acres of woods and open spaces. Three years ago, the Stratton Parks Department (Stratton) carved out miles of trails to allow visitors to hike the property and enjoy nature. To make that experience more enjoyable for visitors and available to school groups, Stratton decided to offer guided tours that have proven popular....

  • please answer question #4 The Stratton Township Park The Stratton Township Park is located on a...

    please answer question #4 The Stratton Township Park The Stratton Township Park is located on a piece of property that contains two golf courses, a swimming pool, and 800 acres of woods and open spaces. Three years ago, the Stratton Parks Department (Stratton) carved out miles of trails to allow visitors to hike the property and enjoy nature. To make that experience more enjoyable for visitors and available to school groups, Stratton decided to offer guided tours that have proven...

  • Gleim 6 Deductions from AGI [1] Which one of the following expenses does not qualify as...

    Gleim 6 Deductions from AGI [1] Which one of the following expenses does not qualify as a deductible medical expense? A. Cost of long-term care for a developmentally disabled person in a relative’s home. B. Special school for a deaf child to learn lip reading. C. Cost of elevator installed for individual who had heart bypass surgery (in excess of increase in value of individual’s home). D. Cost and care of guide dogs used by a blind person in his...

  • Comprehensive Income Tax Course: Module 1 4. Randy turned 16 last year and had his first...

    Comprehensive Income Tax Course: Module 1 4. Randy turned 16 last year and had his first summer job. Even though his parents are claiming him as a dependent he wants to file a return in order to get his refund. He receives his W-2 and decides he can do his own return using form 1040-EZ. Which of the following information is not found on a Form W-2? a) The taxpayer’s Social Security number b) The taxpayer’s wages, tips and other...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT