This is what I have todo and what I have so far can someone please help me to do
ID: 3618633 • Letter: T
Question
This is what I have todo and what I have so far can someone please help me to do what Immissing. Im not sure how to finish it.It is compailing so far :)
Joe's Automotive
Joe's Automotive performs the following routine maintenanceservices:
* Oil change - $26.00
* Lube job - $18.00
* Radiator flush - $30.00
* Transmission flush - $80.00
* Inspection - $15.00
* Muffler replacement - $100.00
* Tire rotation - $20.00
Joe also performs other non routine services and charges for partsand for labor ($20 per hour). Create a GUI application thatdisplays the total for a customer's visit to Joe's. import javax.swing.*;
import java.awt.*;
public class JoesAutomotive extends JPanel {
private static final long serialVersionUID = 1L;
public final double Oil_change1 = 26.00;
public final double Lube_job1 = 18.00;
public final double Radiator_flush1 = 30.00;
public final double Transmission_flush1 = 80.00;
public final double Inspection1 = 15.00;
public final double Muffler_replacement1 = 100.00;
public final double Tire_rotation1 = 20.00;
private JCheckBox Oil_change;
private JCheckBox Lube_job;
private JCheckBox Radiator_flush;
private JCheckBox Transmission_flush;
private JCheckBox Inspection;
private JCheckBox Muffler_replacement;
private JCheckBox Tire_rotation;
public JoesAutomotive() {
setLayout(new GridLayout(4, 0));
Oil_change = new JCheckBox("Oil change");
Lube_job = new JCheckBox("Lube job");
Radiator_flush = new JCheckBox("Radiator flush");
Transmission_flush = new JCheckBox("Transmission flush");
Inspection = new JCheckBox("Inspection");
Muffler_replacement = new JCheckBox("Muffler_replacement");
Tire_rotation = new JCheckBox("Tire_rotation");
setBorder(BorderFactory.createTitledBorder("Toppings"));
add(Oil_change);
add(Lube_job);
add(Radiator_flush);
add(Transmission_flush);
add(Inspection);
add(Muffler_replacement);
add(Tire_rotation);
}
public double getMaintenanceCost() {
double MaintenanceCost = 0.0;
if (Oil_change.isSelected())
MaintenanceCost += Oil_change1;
if (Lube_job.isSelected())
MaintenanceCost += Lube_job1;
if (Radiator_flush.isSelected())
MaintenanceCost += Radiator_flush1;
if (Transmission_flush.isSelected())
MaintenanceCost += Transmission_flush1;
if (Inspection.isSelected())
MaintenanceCost += Inspection1;
if (Inspection.isSelected())
MaintenanceCost += Muffler_replacement1;
if (Inspection.isSelected())
MaintenanceCost += Tire_rotation1;
return MaintenanceCost;
}
}
Explanation / Answer
x.HYou're almost done. You just need to add an action listener and a driver class that will implement the JFrame. Everything I added is commented with this: /********** text here *************/ I just added a few components, a main method to test the code, and an action listener. Hope this helps. Let me know if you have any questions/comments. Thanks */ package JoesAutomotive; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class JoesAutomotive extends JPanel { private static final long serialVersionUID = 1L; public final double Oil_change1 = 26.00; public final double Lube_job1 = 18.00; public final double Radiator_flush1 = 30.00; public final double Transmission_flush1 = 80.00; public final double Inspection1 = 15.00; public final double Muffler_replacement1 = 100.00; public final double Tire_rotation1 = 20.00; private JCheckBox Oil_change; private JCheckBox Lube_job; private JCheckBox Radiator_flush; private JCheckBox Transmission_flush; private JCheckBox Inspection; private JCheckBox Muffler_replacement; private JCheckBox Tire_rotation; /************** added these components ************************/ private JButton calculate; // added this new button private JTextField calcTextField; // added this text field for the calcTextField public JoesAutomotive() { setLayout(new GridLayout(4, 0)); Oil_change = new JCheckBox("Oil change"); Lube_job = new JCheckBox("Lube job"); Radiator_flush = new JCheckBox("Radiator flush"); Transmission_flush = new JCheckBox("Transmission flush"); Inspection = new JCheckBox("Inspection"); Muffler_replacement = new JCheckBox("Muffler_replacement"); Tire_rotation = new JCheckBox("Tire_rotation"); setBorder(BorderFactory.createTitledBorder("Toppings")); add(Oil_change); add(Lube_job); add(Radiator_flush); add(Transmission_flush); add(Inspection); add(Muffler_replacement); add(Tire_rotation); /************** added these lines ************************/ calculate = new JButton("Calculate!"); calculate.addActionListener(new ButtonListener()); calcTextField = new JTextField(""); calcTextField.setEditable(false); // so that user cannot edit final data add(calculate); add(calcTextField); } /************** added an action listener ************************/ // this is an inner class for the action listener private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (e.getSource() == calculate) { // if calculate button was clicked actionCalculate(); } } } /************** added this method to calculate the cost ************************/ private void actionCalculate() { double total = 0; if(Oil_change.isSelected()) total = total + Oil_change1; if(Lube_job.isSelected()) total = total + Radiator_flush1; if(Transmission_flush.isSelected()) total = total + Transmission_flush1; if(Inspection.isSelected()) total = total + Inspection1; if(Muffler_replacement.isSelected()) total = total + Muffler_replacement1; if(Tire_rotation.isSelected()) total = total + Tire_rotation1; // converts double to a string and tacks on the dollar sign String sum = "$"+Double.toString(total); calcTextField.setText(sum); } public double getMaintenanceCost() { double MaintenanceCost = 0.0; if (Oil_change.isSelected()) { MaintenanceCost += Oil_change1; } if (Lube_job.isSelected()) { MaintenanceCost += Lube_job1; } if (Radiator_flush.isSelected()) { MaintenanceCost += Radiator_flush1; } if (Transmission_flush.isSelected()) { MaintenanceCost += Transmission_flush1; } if (Inspection.isSelected()) { MaintenanceCost += Inspection1; } &nbs
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.