The second part (where I could use some advice) requires in addition to displaying the total cost, the services purchased and their price need to be displayed to make a full standard invoice listing. The code below compiles and works fine, but if anyone can give me direction to this second part, I would greatly appreciate your help. Thanks in advance! (This is also my first time posting here, so forgive me if the code doesn't look the way it should).
public class BillingDemo
{
public static void main(String[] args)
{
new Billing();
}
}
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import javax.swing.*;
public class Billing extends JFrame
{
private final double TAX_RATE = 0.06;
private Label label;
private Services service;
private PartsAndLabor PAL;
private Greeting greet;
private JPanel buttonPanel;
private JButton calcButton;
private JButton exitButton;
public Billing()
{
super("Oreder Calculator");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
greet = new Greeting();
label = new Label();
service = new Services();
PAL = new PartsAndLabor();
buildButtonPanel();
add(greet, BorderLayout.NORTH);
add(label, BorderLayout.WEST);
add(service, BorderLayout.CENTER);
add(PAL, BorderLayout.EAST);
add(buttonPanel, BorderLayout.SOUTH);
pack();
setVisible(true);
}
private void buildButtonPanel()
{
buttonPanel = new JPanel();
calcButton = new JButton("Calculate");
exitButton = new JButton("Exit");
calcButton.addActionListener(new CalcButtonListener());
exitButton.addActionListener(new ExitButtonListener());
buttonPanel.add(calcButton);
buttonPanel.add(exitButton);
}
private class CalcButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
double total;
total = service.getServiceCost() +
PAL.getLaborCost();
DecimalFormat dollar = new DecimalFormat("0.00");
JOptionPane.showMessageDialog(null, "\nTotal Amount Due: $" + dollar.format(total) + Services.oilChange);
}
}
private class ExitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
}
import javax.swing.*;
public class Greeting extends JPanel
{
public Greeting()
{
JLabel greeting =
new JLabel("Welcome to Joe's Automotive Service Page!");
add(greeting);
}
}
import java.awt.*;
import javax.swing.*;
public class Label extends JPanel
{
private JLabel label1;
public Label()
{
setLayout(new GridLayout(1,1));
label1 = new JLabel("Choose options here:");
add(label1);
}
}
import java.awt.*;
import javax.swing.*;
public class PartsAndLabor extends JPanel
{
public final double OIL_CHANGE_LABOR = 20.00;
public final double LUBE_JOB_LABOR = 20.00;
public final double RADIATOR_FLUSH_LABOR = 20.00;
public final double TRANSMISSION_FLUSH_LABOR = 20.00;
public final double INSPECTION_LABOR = 20.00;
public final double MUFFLER_REPLACEMENT_LABOR = 20.00;
public final double TIRE_ROTATION_LABOR = 20.00;
private JCheckBox oilChange;
private JCheckBox lubeJob;
private JCheckBox radiatorFlush;
private JCheckBox transmissionFlush;
private JCheckBox inspection;
private JCheckBox mufflerReplacement;
private JCheckBox tireRotation;
public PartsAndLabor()
{
setLayout(new GridLayout(7,1));
oilChange = new JCheckBox("Oil Change Labor");
lubeJob = new JCheckBox("Lube Job Labor");
radiatorFlush = new JCheckBox("Radiator Flush Labor");
transmissionFlush = new JCheckBox("Transmission Flush Labor");
inspection = new JCheckBox("Inspection Labor");
mufflerReplacement = new JCheckBox("Muffler Replacement Labor");
tireRotation = new JCheckBox("Tire Rotation Labor");
setBorder(BorderFactory.createTitledBorder("Parts and Labor"));
add(oilChange);
add(lubeJob);
add(radiatorFlush);
add(transmissionFlush);
add(inspection);
add(mufflerReplacement);
add(tireRotation);
}
public double getLaborCost()
{
double laborCost = 0.0;
if (oilChange.isSelected())
laborCost += OIL_CHANGE_LABOR;
if (lubeJob.isSelected())
laborCost += LUBE_JOB_LABOR;
if (radiatorFlush.isSelected())
laborCost += RADIATOR_FLUSH_LABOR;
if (transmissionFlush.isSelected())
laborCost += TRANSMISSION_FLUSH_LABOR;
if (inspection.isSelected())
laborCost += INSPECTION_LABOR;
if (mufflerReplacement.isSelected())
laborCost += MUFFLER_REPLACEMENT_LABOR;
if (tireRotation.isSelected())
laborCost += TIRE_ROTATION_LABOR;
return laborCost;
}
private static void main(String[] ars)
{
PartsAndLabor PAL = new PartsAndLabor();
}
}
import java.awt.*;
import javax.swing.*;
public class Services extends JPanel
{
public final static double OIL_CHANGE = 26.00;
public final double LUBE_JOB = 18.00;
public final double RADIATOR_FLUSH = 30.00;
public final double TRANSMISSION_FLUSH = 80.00;
public final double INSPECTION = 15.00;
public final double MUFFLER_REPLACEMENT = 100.00;
public final double TIRE_ROTATION = 20.00;
private JCheckBox oilChange;
private JCheckBox lubeJob;
private JCheckBox radiatorFlush;
private JCheckBox transmissionFlush;
private JCheckBox inspection;
private JCheckBox mufflerReplacement;
private JCheckBox tireRotation;
public Services()
{
setLayout(new GridLayout(7,1));
oilChange = new JCheckBox("Oil Change");
lubeJob = new JCheckBox("Lube Job");
radiatorFlush = new JCheckBox("Radiator Flush");
transmissionFlush = new JCheckBox("Transmission Flush");
inspection = new JCheckBox("Inspection");
mufflerReplacement = new JCheckBox("Muffler Replacement");
tireRotation = new JCheckBox("Tire Rotation");
setBorder(BorderFactory.createTitledBorder("Services"));
add(oilChange);
add(lubeJob);
add(radiatorFlush);
add(transmissionFlush);
add(inspection);
add(mufflerReplacement);
add(tireRotation);
}
public double getServiceCost()
{
double serviceCost = 0.0;
if (oilChange.isSelected())
serviceCost += OIL_CHANGE;
if (lubeJob.isSelected())
serviceCost += LUBE_JOB;
if (radiatorFlush.isSelected())
serviceCost += RADIATOR_FLUSH;
if (transmissionFlush.isSelected())
serviceCost += TRANSMISSION_FLUSH;
if (inspection.isSelected())
serviceCost += INSPECTION;
if (mufflerReplacement.isSelected())
serviceCost += MUFFLER_REPLACEMENT;
if (tireRotation.isSelected())
serviceCost += TIRE_ROTATION;
return serviceCost;
}
}

New Topic/Question
Reply


MultiQuote



|