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

I am currently working on programming challenge number 4 in chapter 7 and I am h

ID: 3620375 • Letter: I

Question

I am currently working on programming challenge number 4 in chapter 7 and I am having trouble on formatting my GUI to look like the picture. Also I am having trouble with my calculations.
Here is the directions for the question: 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
- 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 business person
- The total allowable expenses for the trip
- The excess that must by paid by the business person, if any
- The amount saved by the business person of the expenses are
under the total allowed 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
- 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 business person
- The total allowable expenses for the trip
- The excess that must by paid by the business person, if any
- The amount saved by the business person of the expenses are
under the total allowed Here is my current code: Thanks In Advance
import javax.swing.*;           //Needed for Swing classes
import java.awt.*;              //Needed for GUI applications
import java.awt.event.*;        //Needed for ActionListener Interface
import java.text.DecimalFormat; //Needed for formatting decimal numbers


//Create a class called TravelExpenses that inherits from JFrame.
public class TravelExpenses extends JFrame
{
      private JPanel panelNorth;                                                                      
      private JLabel messageLabelGreeting;                                                           
      private JPanel panelCenter;
      private JLabel messageLabelNumDays;                                                              
      private JLabel messageLabelAirfare;                                                              
      private JLabel messageLabelRental;                                                          
      private JLabel messageLabelMiles;                                                          
      private JLabel messageLabelParking;                                                              
      private JLabel messageLabelTaxi;                                                              
      private JLabel messageLabelRegistration;                                                      
      private JLabel messageLabelLodging;                                                              
      private JTextField numDaysTextField;                                                              
      private JTextField airfareTextField;                                                          
      private JTextField rentalTextField;                                                                  
      private JTextField milesTextField;                                                                  
      private JTextField parkingTextField;                                                              
      private JTextField taxiTextField;                                                                  
      private JTextField registrationTextField;                                                          
      private JTextField lodgingTextField;                                                              
      private JPanel panelSouth;                                                                      
      private JButton calcButton;                                                                       
      private final int WINDOW_WIDTH = 500;                                                                   
      private final int WINDOW_HEIGHT = 500;
  
   /*
    Constructor +TravelExpenses()
   */
   public TravelExpenses()
   {
        //Set the title of the window to Travel Expense Calculator.
   setTitle("Travel Expense Calculator");  
      
   //Set the size of the window using the constants.
   setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
  
   //Specify what happens when the close button is clicked.
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
   //Get the content pane of the JFrame and set the layout manager to border layout.
   getContentPane().setLayout(new BorderLayout());
  
   //Create a greeting label that contains the message import javax.swing.*;           //Needed for Swing classes
import java.awt.*;              //Needed for GUI applications
import java.awt.event.*;        //Needed for ActionListener Interface
import java.text.DecimalFormat; //Needed for formatting decimal numbers


//Create a class called TravelExpenses that inherits from JFrame.
public class TravelExpenses extends JFrame
{
      private JPanel panelNorth;                                                                      
      private JLabel messageLabelGreeting;                                                           
      private JPanel panelCenter;
      private JLabel messageLabelNumDays;                                                              
      private JLabel messageLabelAirfare;                                                              
      private JLabel messageLabelRental;                                                          
      private JLabel messageLabelMiles;                                                          
      private JLabel messageLabelParking;                                                              
      private JLabel messageLabelTaxi;                                                              
      private JLabel messageLabelRegistration;                                                      
      private JLabel messageLabelLodging;                                                              
      private JTextField numDaysTextField;                                                              
      private JTextField airfareTextField;                                                          
      private JTextField rentalTextField;                                                                  
      private JTextField milesTextField;                                                                  
      private JTextField parkingTextField;                                                              
      private JTextField taxiTextField;                                                                  
      private JTextField registrationTextField;                                                          
      private JTextField lodgingTextField;                                                              
      private JPanel panelSouth;                                                                      
      private JButton calcButton;                                                                       
      private final int WINDOW_WIDTH = 500;                                                                   
      private final int WINDOW_HEIGHT = 500;
  
   /*
    Constructor +TravelExpenses()
   */
   public TravelExpenses()
   {
        //Set the title of the window to Travel Expense Calculator.
   setTitle("Travel Expense Calculator");  
      
   //Set the size of the window using the constants.
   setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
  
   //Specify what happens when the close button is clicked.
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
   //Get the content pane of the JFrame and set the layout manager to border layout.
   getContentPane().setLayout(new BorderLayout());
  
   //Create a greeting label that contains the message

Explanation / Answer

import javax.swing.*; import java.awt.*; import java.awt.event.*; public class TravelWorksheet extends JFrame { private JTextField dtripTextField; private JTextField dlodgeTextField; private JTextField airfareTextField; private JTextField tcostTextField; private JTextField milesTextField; private JCheckBox airCheckBox; private JCheckBox taxiCheckBox; private JCheckBox pvecCheckBox; private JCheckBox crentCheckBox; private JButton calcButton; private final int WINDOW_WIDTH = 500; private final int WINDOW_HEIGHT = 500; public TravelWorksheet() { setTitle("Travel Wroksheet"); setSize(WINDOW_WIDTH, WINDOW_HEIGHT); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new GridLayout(4, 3)); JTextField dtrip = new JTextField(4); JCheckBox air = new JCheckBox("Air"); JCheckBox crent = new JCheckBox("Car rental"); JCheckBox taxi = new JCheckBox("Taxi"); JCheckBox pvec = new JCheckBox("Personal Vehicle"); JTextField dlodge = new JTextField(4); JTextField airfare = new JTextField(4); JTextField tcost = new JTextField(4); JTextField miles = new JTextField(4); JTextField sfees = new JTextField(4); JTextField pfees = new JTextField(4); JButton calcbutton = new JButton("Calculate"); JLabel label1 = new JLabel("Days on trip."); JLabel label2 = new JLabel("Mode of Travel to destination."); JLabel label3 = new JLabel("Daily Lodging cost."); JLabel label4 = new JLabel("Air Fare Cost."); JLabel label5 = new JLabel("Taxi Cost."); JLabel label6 = new JLabel("miles driven."); JLabel label7 = new JLabel("Seminar or Registration fees."); JLabel label8 = new JLabel("Parking fees."); JLabel label9 = new JLabel("Calculate."); JPanel panel1 = new JPanel(); JPanel panel2 = new JPanel(); JPanel panel3 = new JPanel(); JPanel panel4 = new JPanel(); JPanel panel5 = new JPanel(); JPanel panel6 = new JPanel(); JPanel panel7 = new JPanel(); JPanel panel8 = new JPanel(); JPanel panel9 = new JPanel(); panel1.add(label1); panel2.add(label2); panel3.add(label3); panel4.add(label4); panel5.add(label5); panel6.add(label6); panel7.add(label7); panel8.add(label8); panel9.setLayout(new BorderLayout()); panel1.add(dtrip); panel2.add(air); panel2.add(crent); panel2.add(taxi); panel2.add(pvec); panel3.add(dlodge); panel4.add(airfare); panel5.add(tcost); panel6.add(miles); panel7.add(sfees); panel8.add(pfees); panel9.add(calcButton, BorderLayout.SOUTH); add(panel1); add(panel2); add(panel3); add(panel4); add(panel5); add(panel6); add(panel7); add(panel8); add(panel9); calcButton.addActionListener(new calcButtonListener()); setVisible(true); } private class calcButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { String input; String input1; String input2; String input3; String input4; String input5; String input6; double avalue; double mvalue; double tvalue; double ptax; input = dtripTextField.getText(); input1 = dlodgeTextField.getText(); input2 = airfareTextField.getText(); input3 = tcostTextField.getText(); input4 = dlodgeTextField.getText(); input5 = dlodgeTextField.getText(); input6 = dlodgeTextField.getText(); mvalue = Double.parseDouble(input) * 37; avalue = Double.parseDouble(input) * Double.parseDouble(input1); tvalue = avalue + mvalue; JOptionPane.showMessageDialog(null, " Total money spent on trip is: $" + tvalue + "."); } } public static void main(String[] args) { new TravelWorksheet(); } }