Question: I need a javadoc comment for my following code. This is what I need for the javadoc comments Author - Nas. The Date - 2
I need a javadoc comment for my following code. This is what I need for the javadoc comments AuthorNas. The Date April and the purpose of the program which is to provide a family friendly interface for inputtig trip details and calculatees the toal trip cost based on the provided information. import javax.swing.;
import java.awt.;
import java.awt.event.;
public class Project extends JFrame
private JLabel distanceLabel, gasCostLabel, gasMileageLabel, resultLabel;
private JTextField distanceField, gasCostField;
private JComboBox distanceUnitComboBox, gasCostUnitComboBox, gasMileageUnitComboBox;
private JButton calculateButton;
public Project
setTitleTrip Cost Estimator";
setDefaultCloseOperationJFrameEXITONCLOSE;
setSize;
setLocationRelativeTonull; Center the window
distanceLabel new JLabelDistance:;
gasCostLabel new JLabelGasoline Cost:";
gasMileageLabel new JLabelGas Mileage:";
resultLabel new JLabelTotal Trip Cost:";
distanceField new JTextField;
gasCostField new JTextField;
String distanceUnits Miles "Kilometers";
distanceUnitComboBox new JComboBoxdistanceUnits;
String gasCostUnits Dollars per Gallon", "Dollars per Liter";
gasCostUnitComboBox new JComboBoxgasCostUnits;
String gasMileageUnits Miles per Gallon", "Kilometers per Liter";
gasMileageUnitComboBox new JComboBoxgasMileageUnits;
calculateButton new JButtonCalculate;
calculateButton.addActionListenernew CalculateButtonListener;
JPanel panel new JPanelnew GridLayout;
panel.adddistanceLabel;
panel.adddistanceField;
panel.adddistanceUnitComboBox;
panel.addnew JLabel; Empty space
panel.addgasCostLabel;
panel.addgasCostField;
panel.addgasCostUnitComboBox;
panel.addnew JLabel; Empty space
panel.addgasMileageLabel;
panel.addnew JLabel; Empty space
panel.addgasMileageUnitComboBox;
panel.addnew JLabel; Empty space
panel.addcalculateButton;
panel.addresultLabel;
panel.addnew JLabel; Empty space
setLayoutnew BorderLayout;
addpanel BorderLayout.CENTER;
private class CalculateButtonListener implements ActionListener
public void actionPerformedActionEvent e
Get user input
double distance Double.parseDoubledistanceFieldgetText;
double gasCost Double.parseDoublegasCostFieldgetText;
Convert units
if distanceUnitComboBoxgetSelectedIndex Kilometers
distance ; Convert kilometers to miles
if gasCostUnitComboBoxgetSelectedIndex Dollars per liter
gasCost ; Convert dollars per liter to dollars per gallon
Calculate total trip cost
double totalCost TripCost.calculateTripCostdistance gasCost, gasMileageUnitComboBox.getSelectedIndex;
Display result
resultLabel.setTextTotal Trip Cost: $ String.formatf totalCost;
public static void mainString args
SwingUtilities.invokeLaternew Runnable
public void run
new ProjectsetVisibletrue;
;
class TripCost
public static double calculateTripCostdouble distance, double gasCost, int gasMileageUnitIndex
double gasMileage;
if gasMileageUnitIndex Miles per gallon
gasMileage ; Example value, you can change this according to your needs
else Kilometers per liter
gasMileage ; Example value, you can change this according to your needs
double totalCost distance gasMileage gasCost;
return totalCost;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
