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

Hello I am working on a Travel Expenses Java Program. I have most of it so far b

ID: 3759769 • Letter: H

Question

Hello I am working on a Travel Expenses Java Program. I have most of it so far but keep getting errors, Please help!!!!

Problem:

Write a TravelExpenses class that prompts the user in a JFrame using grid layout for the following inputs (all doubles, except the first):

Number of days on the trip

Amount of airfare (if any)

Amount of car rental charges (if any)

Number of miles driven in personal car (if any)

Amount of parking fees (if any)

Amount of taxi charges (if any)

Amount of tolls (if any)

Conference or seminar fees (if any)

Meal charges

Lodging charges

The company reimburses all travel expenses subject to the following maximums (a-d are restrictions on the maximum the company will reimburse the employee):

$37 per day for meals

Up to $10 per day parking fees

Up to $20 per day taxi charges

Up to $95 per day for lodging

If a personal vehicle is used, $0.27 per mile driven

If an employee goes over in a category, then the employee is responsible for paying the excess out-of-pocket. Being under in another category does NOT offset the excess.

The application should calculate and display:

Total expenses incurred,

The allowable expenses for the trip,

The excess that must be paid by the traveler, if any.

Program so far:

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();
}

}

Explanation / Answer

your main problem is that you declare the button with all lower

calcbutton

but you add the listener to a button which has an uppercase letter
calcButton.add....

change your top declaration to
calcButton

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