Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the Pseudocode (refresh from chapter 1) and the UML diagram (refresh fr

ID: 3855908 • Letter: C

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 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();

}

}

Explanation / Answer

Public Class Form1 002     ' This application calculates the total order for services, parts and labor 003     ' at Joe's Automotive. This application uses several functions to calculate the total cost. 004     Const decTAX_RATE As Decimal = 0.06D ' Tax rate on parts 005 006     Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles btnCalculate.Click 007         ' This proedure calculates the total of an order. 008 009         Dim decServicesLabor As Decimal ' Holds the labor and services total 010         Dim decParts As Decimal ' holds the parts order 011         Dim decTax As Decimal ' holds the tax on parts 012         Dim decTotal As Decimal ' holds the order total 013 014         decServicesLabor = OilLubeCharges() + FlushCharges() + MiscCharges() + OtherCharges() 015         decParts = PartsCost() 016         decTax = CalcTax(decParts) 017         decTotal = decServicesLabor + decTax 018 019         lblServicesLabor.Text = decServicesLabor.ToString("c") 020         lblParts.Text = decParts.ToString("c") 021         lblTax.Text = decTax.ToString("c") 022         lblTotal.Text = decTotal.ToString("c") 023 024     End Sub 025 026     Function PartsIsValid() As Boolean 027         ' Declare a value to temporarily hold the parts value. 028         Dim decTempValue As Decimal 029         If Not Decimal.TryParse(txtParts.Text, decTempValue) Then 030             MessageBox.Show("Enter a numeric value for the parts cost.") 031             Return False 032         End If 033         If decTempValue < 0 Then 034             MessageBox.Show("Enter a positive value for the parts cost.") 035         End If 036 037         ' If we have made it this far, the value is valid, so return true. 038         Return True 039     End Function 040     Function LaborIsValid() As Boolean 041         ' Declare a value to temporarily hold the labor value. 042         Dim decTempValue2 As Decimal 043         If Not Decimal.TryParse(txtLabor.Text, decTempValue2) Then 044             MessageBox.Show("Enter a numeric value for the labor cost.") 045             Return False 046         End If 047           048         If decTempValue2 < 0 Then 049             MessageBox.Show("Enter a positive value for the labor cost.") 050         End If 051         ' If we have made it this far, the value is valid, so return true. 052         Return True 053     End Function 054 055 056     Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles btnClear.Click 057         ' This procedure resets the controls to default values 058 059         ResetOilLubeCharges() 060         ResetFlushCharges() 061         ResetMiscCharges() 062         ' Clears the text Boxes in the Parts and Labor box 063         txtParts.Text = "" 064         txtLabor.Text = "" 065         ' Clears the boxes in the Summary Box. 066         lblServicesLabor.Text = "" 067         lblTax.Text = "" 068         lblParts.Text = "" 069         lblTotal.Text = "" 070 071     End Sub 072 073     Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles btnExit.Click 074         ' End the application. 075         Me.Close() 076     End Sub 077     Function OilLubeCharges() As Decimal 078         'This function returns the cost of the Oil and Lube Charges. 079 080         Dim decCostOfOilLube As Decimal = 0 081 082         If chkOilChange.Checked = True Then 083             decCostOfOilLube += 26D 084         End If 085         If chkLubeJob.Checked = True Then 086             decCostOfOilLube += 18D 087         End If 088         Return decCostOfOilLube 089     End Function 090     Function FlushCharges() As Decimal 091         ' This function returns the cost of the Flush Charges. 092 093         Dim decCostOfFlush As Decimal = 0 094 095         If chkRadiatorFlush.Checked = True Then 096             decCostOfFlush += 30D 097         End If 098         If chkTransmissionFlush.Checked = True Then 099             decCostOfFlush += 80D 100         End If 101         Return decCostOfFlush 102     End Function 103     Function MiscCharges() As Decimal 104         ' This function returns the cost of misc. 105         Dim decCostOfMisc As Decimal = 0 106 107         If chkInspection.Checked = True Then 108             decCostOfMisc += 15D 109         End If 110         If chkReplaceMuffler.Checked = True Then 111             decCostOfMisc += 100D 112         End If 113         If chkTireRotation.Checked = True Then 114             decCostOfMisc += 20D 115         End If 116         Return decCostOfMisc 117     End Function 118     Function PartsCost() As Decimal 119         ' This function returns the cost of parts. 120 121     End Function 122     Function OtherCharges() As Decimal 123         ' This function returns the cost of labor. 124 125     End Function 126     Function CalcTax(ByVal decAmount As Decimal) As Decimal 127         ' this function receives the parts amount. It 128         ' calculates and returns the parts tax, based 129         ' on the parts amount. 130         Return decAmount * decTAX_RATE 131     End Function 132     Private Sub ResetOilLubeCharges() 133         ' This procedure resets the Oil and Lube selection. 134         chkOilChange.Checked = False 135         chkLubeJob.Checked = False 136     End Sub 137 138     Sub ResetFlushCharges() 139         ' this procedure resets the flush charges. 140         chkRadiatorFlush.Checked = False 141         chkTransmissionFlush.Checked = False 142     End Sub 143 144     Sub ResetMiscCharges() 145         ' this procedure resets misc charges. 146 147         chkInspection.Checked = False 148         chkReplaceMuffler.Checked = False 149         chkTireRotation.Checked = False 150 151     End Sub 152 153 154 155 156 157 End Class
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote