Question: Complete the Pseudocode (refresh from chapter 1) and the UML diagram (refresh from chapter 6) for a programming challenge (other than programming challenge 1) from
Complete the Pseudocode (refresh from chapter 1) and the UML diagram (refresh from chapter 6) for a programming challenge (other than programming challenge 1) from the end of chapter 12.
Q-2 Joe's automotive perform the following routine maintance services:
oil change - $26.00
lube job - $18.00
Radiator flush - $30.00
Transmission flush - $80.00
Inspection - $15.00
Tire rotation - $20.00
Joe also perform other nonroutine service and charges for parts and for labor ($20 per hours). Create a GUI application that displays the total for a customer's visit to Joe's.
Program:
//This is For the services part import java.awt.*; import javax.swing.*; public class Service extends JPanel { // The following constants are used to indicate // the cost of services for automotive. public final double oilchange = 26.00; public final double lubejob = 18.00; public final double radiatorflush = 30.00; public final double transmissionflush = 80.00; public final double inspection= 15.00; public final double mufflerreplacement = 100.00; public final double tirerotation = 20.00; // for text field. private JTextField calcTextField; // check boxes listed for the available services. private JCheckBox oilchange; private JCheckBox lubejob; private JCheckBox radiatorflush; private JCheckBox transmissionflush; private JCheckBox inspection; private JCheckBox mufflerreplacement; private JCheckBox tirerotation;
// Constructor
public Service() {
// gridlayout with seven rows and one column. setLayout(new GridLayout(7,1 ));
// Create the check boxes. oilchange = new JCheckBox("Oil Change ($26.00)");
lubejob = new JCheckBox("Lube Job ($18.00)");
radiatorflush = new JCheckBox("Radiator Flush ($30.00)");
transmissionflush = new JCheckBox("Transmission Flush ($80.00)");
inspection = new JCheckBox("Inspection ($15.00)");
mufflerreplacement = new JCheckBox("Muffler Replacement ($100.00)");
tirerotation = new JCheckBox("Tire Rotation ($20.00)");
// Add a border around the panel. setBorder(BorderFactory.createTitledBorder("Routine Services"));
// Add the check boxes to this panel.
add(oilchange);
add(lubejob);
add(radiatorflush);
add(transmissionflush);
add(inspection);
add(mufflerreplacement);
add(tirerotation); }
//This method returns the cost of the selected services.
public double actionCalculate() { double total = 0; if(oilchange.isSelected()) total = total + oilchange;
if(lubejob.isSelected()) total = total + lubejob;
if(radiatorflush.isSelected()) total = total + radiatorflush;
if(transmissionflush.isSelected()) total = total + transmissionflush;
if(Inspection.isSelected()) total = total + inspection;
if(mufflerreplacement.isSelected()) total = total + mufflerreplacement;
if(tirerotation.isSelected()) total = total + tirerotation; return total;
} }
//This for NonRoutine Services import java.awt.*; import javax.swing.*; public class NonService extends JPanel { public final double perhourcharge = 20.00; //per hour labor cost private JLabel partslabel; //references parts charges label private JLabel laborlabel; //references hours of labor label private JTextField partsTextField; //references parts charges text field private JTextField laborTextField; //references hours of labor text field private JPanel panel; public NonService() { //Create labels partsLabel = new JLabel("Parts Charges:"); laborLabel = new JLabel("Hours of Labor:");
// Create the text Fields partsTextField = new JTextField(10); laborTextField = new JTextField(10);
// Add a border around the panel setBorder(BorderFactory.createTitledBorder("Nonroutine services"));
add(partsLabel); add(partsTextField); add(laborLabel); add(laborTextField);
panel = new JPanel(); panel.setLayout(new GridLayout(3,2)); setLayout(new GridLayout(2, 2)); } }
//This calculates everthing and creates the GUI App
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.text.DecimalFormat;
//The CalculatorGUI class creates the GUI for joe's automotive application.
public class CalculatorGUI extends JFrame {
// custom panel objects.
//services part. private Service sc; private NonService ns;
// The following variables will reference objects
private JPanel buttonPanel; private JButton calcButton; private JButton exitButton;
// Constructor
public CalculatorGUI() { // Display title. super("Joe's Automotive"); setLocationRelativeTo(null); // Specify an action for the close button. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create a BorderLayout manager for // the content pane. setLayout(new BorderLayout());
// Create the custom panels. sc = new Service(); ns = new NonService();
// Call the buildButtonPanel method to // create the button panel. buildButtonPanel();
// Add the components to the content pane. add(sc, BorderLayout.NORTH);
add(ns, BorderLayout.SOUTH);
// Pack the contents of the window and display it. pack(); setVisible(true); }
//The buildbuttonpanel method builds the button panel.
private void buildButtonPanel() { // Create a panel for the buttons. buttonPanel = new JPanel();
// Create the buttons. calcButton = new JButton("Calculate Charges"); exitButton = new JButton("Exit");
// Register the action listeners. calcButton.addActionListener(new CalcButtonListener()); exitButton.addActionListener(new ExitButtonListener());
// Add the buttons to the button panel. buttonPanel.add(calcButton); buttonPanel.add(exitButton);
}
// Private inner class that handles the event when the user clicks the Calculate button.
private class CalcButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) {
double total; // The total of order
// Calculate the subtotal. total = sc.actionCalculate() + ns.getNonroutineServicesCost();
// creating a decimalformat object to format
DecimalFormat dollar = new DecimalFormat("0.00");
// Display the charges. JOptionPane.showMessageDialog(null, "Total: $" + dollar.format(total) );
} }
// private inner class that handles the event when the user clicks the exit button.
private class ExitButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) {
System.exit(0); } } public static void main(String args[])
{
new CalculatorGUI();
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
