Joe\'s Auto shop performs the following service\'s: Oil change - $26.00 Lube job
ID: 3640450 • Letter: J
Question
Joe's Auto shop performs the following service's: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 parts and for labor ($20.00 an hour). Create a GUI application that displays the total for a customer's visit to Joe's. I have the following code but have hit a road bump in getting it to function any help would be great.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.text.DecimalFormat;
@SuppressWarnings("serial")
public class JoesAutoShop extends JFrame implements ItemListener, ActionListener
{
private JPanel boxPanel;
private JPanel hourPanel;
private JPanel totalPanel;
private JCheckBox OilChange;
private double OIL = 26.00;
private JCheckBox LubeJob;
private double LUBE = 18.00;
private JCheckBox Radiator;
private double RAD = 30.00;
private JCheckBox Transmission;
private double TRANS = 80.00;
private JCheckBox Inspection;
private double INSP = 15.00;
private JCheckBox Muffler;
private double MUF = 100.00;
private JCheckBox TireRot;
private double TIRE = 20.00;
private JTextField numHours;
private JLabel total;
private JButton Calculate;
DecimalFormat dollar = new DecimalFormat("$0.00");
public JoesAutoShop()
{
setSize(300,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Joes Auto Shop");
numHours = new JTextField(10);
numHours.addActionListener(this);
Calculate = new JButton("Calculate");
Calculate.addActionListener(this);
OilChange = new JCheckBox("Oil Change: $26.00");
OilChange.addItemListener(this);
LubeJob = new JCheckBox("Lube Jobe: $18.00");
LubeJob.addItemListener(this);
Radiator = new JCheckBox("Radiator flush: $30.00");
Radiator.addItemListener(this);
Transmission = new JCheckBox("Transmission flush: $80.00");
Transmission.addItemListener(this);
Inspection = new JCheckBox("Inspection: $15.00");
Inspection.addItemListener(this);
Muffler = new JCheckBox("Muffler replacement: $100.00");
Muffler.addItemListener(this);
TireRot = new JCheckBox("Tire rotation: $20.00");
TireRot.addItemListener(this);
JTextField numHours = new JTextField(10);
boxPanel.add(OilChange);
boxPanel.add(LubeJob);
boxPanel.add(Radiator);
boxPanel.add(Transmission);
boxPanel.add(Inspection);
boxPanel.add(Muffler);
boxPanel.add(TireRot);
add(boxPanel);
add(hourPanel);
add(totalPanel);
setVisible(true);
}
public double getBoxCost()
{
double boxCost = 0;
if (OilChange.isSelected())
boxCost += OIL;
if (LubeJob.isSelected())
boxCost += LUBE;
if (Radiator.isSelected())
boxCost += RAD;
if (Transmission.isSelected())
boxCost += TRANS;
if (Inspection.isSelected())
boxCost += INSP;
if (Muffler.isSelected())
boxCost += MUF;
if (TireRot.isSelected())
boxCost += TIRE;
return boxCost;
}
public double getHoursCost()
{
String input;
double hoursTotal = 0;
input = numHours.getText();
hoursTotal += (Double.parseDouble(input) * 20);
return hoursTotal;
}
public void TotalCost()
{
String TotalCost;
TotalCost = Double.toString(getBoxCost() + getHoursCost());
total.setText(TotalCost);
}
public void itemStateChanged(ItemEvent e)
{
}
public void actionPerformed(ActionEvent e)
{
}
public static void main(String[] Args)
{
JoesAutoShop s1 = new JoesAutoShop();
}
}
Explanation / Answer
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.text.DecimalFormat;
@SuppressWarnings("serial")
public class JoesAutoShop extends JFrame implements ItemListener, ActionListener {
private static final double OIL_CHANGE = 26.00;
private static final double LUBE_JOB = 18.00;
private static final double RADIATOR_FLUSH = 30.00;
private static final double TRANSMISSION_FLUSH = 80.00;
private static final double INSPECTION = 15.00;
private static final double MUFFLER_REPLACEMENT = 100.00;
private static final double TIRE_ROTATION = 20.00;
private JPanel boxPanel;
private JCheckBox oilChange;
private JCheckBox lubeJob;
private JCheckBox radiatorFlush;
private JCheckBox transmissionFlush;
private JCheckBox inspection;
private JCheckBox mufflerReplacement;
private JCheckBox tireRotation;
private JTextField totalHoursWorked;
private JLabel hoursLabel;
private JButton calculate;
private JLabel totalAmount;
public JoesAutoShop() {
setSize(300, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Joes Auto Shop");
setLayout(new BorderLayout());
boxPanel = new JPanel(new GridLayout(0, 1));
totalHoursWorked = new JTextField(10);
totalHoursWorked.setText("0");
hoursLabel = new JLabel("Enter Hours Worked :");
calculate = new JButton("Calculate");
calculate.addActionListener(this);
oilChange = new JCheckBox("Oil Change: $26.00");
oilChange.setName("OIL");
oilChange.addItemListener(this);
lubeJob = new JCheckBox("Lube Jobe: $18.00");
lubeJob.setName("LUBE");
lubeJob.addItemListener(this);
radiatorFlush = new JCheckBox("Radiator flush: $30.00");
radiatorFlush.setName("RADIATOR");
radiatorFlush.addItemListener(this);
transmissionFlush = new JCheckBox("Transmission flush: $80.00");
transmissionFlush.setName("TRANSMISSION");
transmissionFlush.addItemListener(this);
inspection = new JCheckBox("Inspection: $15.00");
inspection.setName("INSPECTION");
inspection.addItemListener(this);
mufflerReplacement = new JCheckBox("Muffler replacement: $100.00");
mufflerReplacement.setName("MUFFLER");
mufflerReplacement.addItemListener(this);
tireRotation = new JCheckBox("Tire rotation: $20.00");
tireRotation.setName("ROTATION");
tireRotation.addItemListener(this);
Font displayFont = new Font("Serif", Font.BOLD, 18);
totalAmount = new JLabel();
totalAmount.setFont(displayFont);
totalAmount.setText("Total Amount : $0.00");
JTextField numHours = new JTextField(10);
boxPanel.add(oilChange);
boxPanel.add(lubeJob);
boxPanel.add(radiatorFlush);
boxPanel.add(transmissionFlush);
boxPanel.add(inspection);
boxPanel.add(mufflerReplacement);
boxPanel.add(tireRotation);
boxPanel.add(calculate);
boxPanel.add(hoursLabel);
boxPanel.add(totalHoursWorked);
boxPanel.add(totalAmount);
add(boxPanel, BorderLayout.CENTER);
setVisible(true);
}
public double getBoxCost() {
double boxCost = 0;
if (oilChange.isSelected()) {
boxCost += OIL_CHANGE;
}
if (lubeJob.isSelected()) {
boxCost += LUBE_JOB;
}
if (radiatorFlush.isSelected()) {
boxCost += RADIATOR_FLUSH;
}
if (transmissionFlush.isSelected()) {
boxCost += TRANSMISSION_FLUSH;
}
if (inspection.isSelected()) {
boxCost += INSPECTION;
}
if (mufflerReplacement.isSelected()) {
boxCost += MUFFLER_REPLACEMENT;
}
if (tireRotation.isSelected()) {
boxCost += TIRE_ROTATION;
}
return boxCost;
}
public double getHoursCost() {
String input;
double hoursTotal = 0;
input = totalHoursWorked.getText();
hoursTotal += (Integer.parseInt(input) * 20);
System.out.println(hoursTotal);
return hoursTotal;
}
public void getTotalCost() {
double total = getBoxCost() + getHoursCost();
totalAmount.setText("Total Amount : $"+total);
}
public void itemStateChanged(ItemEvent e) {
getTotalCost();
}
public void actionPerformed(ActionEvent e) {
getTotalCost();
}
public static void main(String[] Args) {
JoesAutoShop s1 = new JoesAutoShop();
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.text.DecimalFormat;
@SuppressWarnings("serial")
public class JoesAutoShop extends JFrame implements ItemListener, ActionListener {
private static final double OIL_CHANGE = 26.00;
private static final double LUBE_JOB = 18.00;
private static final double RADIATOR_FLUSH = 30.00;
private static final double TRANSMISSION_FLUSH = 80.00;
private static final double INSPECTION = 15.00;
private static final double MUFFLER_REPLACEMENT = 100.00;
private static final double TIRE_ROTATION = 20.00;
private JPanel boxPanel;
private JCheckBox oilChange;
private JCheckBox lubeJob;
private JCheckBox radiatorFlush;
private JCheckBox transmissionFlush;
private JCheckBox inspection;
private JCheckBox mufflerReplacement;
private JCheckBox tireRotation;
private JTextField totalHoursWorked;
private JLabel hoursLabel;
private JButton calculate;
private JLabel totalAmount;
public JoesAutoShop() {
setSize(300, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Joes Auto Shop");
setLayout(new BorderLayout());
boxPanel = new JPanel(new GridLayout(0, 1));
totalHoursWorked = new JTextField(10);
totalHoursWorked.setText("0");
hoursLabel = new JLabel("Enter Hours Worked :");
calculate = new JButton("Calculate");
calculate.addActionListener(this);
oilChange = new JCheckBox("Oil Change: $26.00");
oilChange.setName("OIL");
oilChange.addItemListener(this);
lubeJob = new JCheckBox("Lube Jobe: $18.00");
lubeJob.setName("LUBE");
lubeJob.addItemListener(this);
radiatorFlush = new JCheckBox("Radiator flush: $30.00");
radiatorFlush.setName("RADIATOR");
radiatorFlush.addItemListener(this);
transmissionFlush = new JCheckBox("Transmission flush: $80.00");
transmissionFlush.setName("TRANSMISSION");
transmissionFlush.addItemListener(this);
inspection = new JCheckBox("Inspection: $15.00");
inspection.setName("INSPECTION");
inspection.addItemListener(this);
mufflerReplacement = new JCheckBox("Muffler replacement: $100.00");
mufflerReplacement.setName("MUFFLER");
mufflerReplacement.addItemListener(this);
tireRotation = new JCheckBox("Tire rotation: $20.00");
tireRotation.setName("ROTATION");
tireRotation.addItemListener(this);
Font displayFont = new Font("Serif", Font.BOLD, 18);
totalAmount = new JLabel();
totalAmount.setFont(displayFont);
totalAmount.setText("Total Amount : $0.00");
JTextField numHours = new JTextField(10);
boxPanel.add(oilChange);
boxPanel.add(lubeJob);
boxPanel.add(radiatorFlush);
boxPanel.add(transmissionFlush);
boxPanel.add(inspection);
boxPanel.add(mufflerReplacement);
boxPanel.add(tireRotation);
boxPanel.add(calculate);
boxPanel.add(hoursLabel);
boxPanel.add(totalHoursWorked);
boxPanel.add(totalAmount);
add(boxPanel, BorderLayout.CENTER);
setVisible(true);
}
public double getBoxCost() {
double boxCost = 0;
if (oilChange.isSelected()) {
boxCost += OIL_CHANGE;
}
if (lubeJob.isSelected()) {
boxCost += LUBE_JOB;
}
if (radiatorFlush.isSelected()) {
boxCost += RADIATOR_FLUSH;
}
if (transmissionFlush.isSelected()) {
boxCost += TRANSMISSION_FLUSH;
}
if (inspection.isSelected()) {
boxCost += INSPECTION;
}
if (mufflerReplacement.isSelected()) {
boxCost += MUFFLER_REPLACEMENT;
}
if (tireRotation.isSelected()) {
boxCost += TIRE_ROTATION;
}
return boxCost;
}
public double getHoursCost() {
String input;
double hoursTotal = 0;
input = totalHoursWorked.getText();
hoursTotal += (Integer.parseInt(input) * 20);
System.out.println(hoursTotal);
return hoursTotal;
}
public void getTotalCost() {
double total = getBoxCost() + getHoursCost();
totalAmount.setText("Total Amount : $"+total);
}
public void itemStateChanged(ItemEvent e) {
getTotalCost();
}
public void actionPerformed(ActionEvent e) {
getTotalCost();
}
public static void main(String[] Args) {
JoesAutoShop s1 = new JoesAutoShop();
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.