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

question I need help with however, I need to write out the GUI with different cl

ID: 669452 • Letter: Q

Question

question I need help with however, I need to write out the GUI with different classes. The bottom of this page contains code that I need to closely resemble the Bagel GUI with the CAR GUI. Please reaad instructions carefully. Thank You

6. Joe ’s Au tomotive
Joe’s Automotive performs the following routine maintenance services:
• Oil change—$26.00
• Lube job—$18.00
• Radiator flush —$30.00
• Transmission flush —$80.00
• Inspect ion —$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 per hour).
Create a GU I application that displays the total for a customer’s visit to Joe’s.

I need three classes (Chp07PC06.java, RoutinePanel.java, NonRoutinePanel.java)

GreetingPanel.java

BagelPanel.java

Topping Panel.java

CoffePanel.java

OrderCalculator.java

Bagel.java

This is the code that I need to make the mechanic GUI. If you can use this code and work around with it to make the mechanic GUI functional, I will appreciate it.

Thank You.

Explanation / Answer


GreetingPanel.java
import javax.swing.*;

/**
The GreetingPanel class displays a greeting in a panel.
*/

public class GreetingPanel extends JPanel
{
private JLabel greeting; // To display a greeting

/**
Constructor
*/

public GreetingPanel()
{
// Create the label.
greeting = new JLabel("Welcome to Joe Automotive Service Shop");

// Add the label to this panel.
add(greeting);
}
}

===================================================================================

RoutinePanel.java

import javax.swing.*;
import java.awt.*;

/**
The RoutinePanel class allows the user to select
the services offered.
*/

public class RoutinePanel extends JPanel
{
// The following constants are used to indicate
// the cost of each type of bagel.
public final double Lube_job = 18.00;
public final double Oil_change = 26.00;
public final double Radiator_flush = 30.00;
public final double Transmission_flush = 80.00;
public final double Inspect_ion = 15.00;
public final double Muffle_replace = 100.00;
public final double Tire_rotation = 20.00;

private JRadioButton Lube;
private JRadioButton Oil;
private JRadioButton Radiator;
private JRadioButton Transmission;
private JRadioButton Inspect;
private JRadioButton Muffle;
private JRadioButton Tire;

private ButtonGroup bg; // Radio button group

/**
Constructor
*/

public RoutinePanel()
{
// Create a GridLayout manager with
// seven rows and one column.
setLayout(new GridLayout(7, 1));

// Create the radio buttons.
Lube = new JRadioButton("Lube", true);
Oil = new JRadioButton("Oil");
Radiator=new JRadioButton("Radiator");
Transmission=new JRadioButton("Transmission");
Inspect=new JRadioButton("Inspect");
Muffle=new JRadioButton("Muffle");
Tire=new JRadioButton("Tire");

// Group the radio buttons.
bg = new ButtonGroup();
bg.add(Lube);
bg.add(Oil);
bg.add(Radiator);
bg.add(Transmission);
bg.add(Inspect);
bg.add(Muffle);
bg.add(Tire);

// Add a border around the panel.
setBorder(BorderFactory.createTitledBorder("Automotive Shop"));

// Add the radio buttons to the panel.
add(Lube);
add(Oil);
add(Radiator);
add(Transmission);
add(Inspect);
add(Muffle);
add(Tire);
}

/**
getRoutineCost method
@return The cost of the selected service.
*/

public double getRoutineCost()
{
double Cost = 0.0;

if (Lube.isSelected())
Cost = Lube_job;
else if(Oil.isSelected())
Cost = Oil_change;
else if(Radiator.isSelected())
Cost=Radiator_flush;
else if(Transmission.isSelected())
Cost= Transmission_flush;
else if(Inspect.isSelected())
Cost= Inspect_ion;
else if(Muffle.isSelected())
Cost= Muffle_replace ;
else
Cost=Tire_rotation ;

return Cost;
}
}

===================================================================================

NonRoutinePanel.java

import javax.swing.*;
import java.awt.*;

/**
The NonRoutinePanel class allows the user to select
non routine function of the workshop.
*/

public class NonRoutinePanel extends JPanel
{
// The following constants are used to indicate
// the cost of non routine
/**
Constructor
*/

public NonRoutinePanel()
{
// Create a FlowLayout manager with
// four rows and one column.
setLayout(new FlowLayout());

//Creating the text field to allow the user to enter the value of the number of hours.
double temp=0.0;
JTextField Value = new JTextField("0.0");
Value.setText();

// Add a border around the panel.
setBorder(BorderFactory.createTitledBorder("NonRoutine"));

// Add the text boxe to the panel.
add(Value);

}

/**
getNonRoutineCost method
@return The cost on the number of hours worked.
*/

public double getNonRoutineCost()
{
double Rate = 0.0;
double temp=0.0;
temp=Double.parseDouble(Value.getText()); //Changing the text field value to Double.
Rate=Rate*temp;


return Rate;
}
}

===================================================================================

Now we calculate the total of the order in the main class:-

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;


public class Chp07PC06 extends JFrame {

private JButton calcButton; // To calculate the cost
private JButton exitButton; // To exit the application

/**
Constructor
*/

public Chp07PC06()
{
private RoutinePanel routine; // routine panel
private NonRoutinePanel non_routine; // non routine panel
private GreetingPanel banner; // To display a greeting

// Display a title.
setTitle("Order Calculator");

// Specify an action for the close button.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Create a BorderLayout manager.
setLayout(new BorderLayout());

// Create the custom panels.
banner = new GreetingPanel();
routine = new RoutinePanel();
non_routine = new nonRoutinePanel();

// Create the button panel.
buildButtonPanel();

// Add the components to the content pane.
add(banner);
add(routine);
add(non_routine);
setVisible(true); //Setting the visibility

private void buildButtonPanel()
{
// Create a panel for the buttons.
buttonPanel = new JPanel();

// Create the buttons.
calcButton = new JButton("Calculate");
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)
{
// Variables to hold the subtotal
double subtotal;

// Calculate the subtotal.
subtotal = routine.getRoutineCost() +
non_routine.getNonRoutineCost() ;

// Create a DecimalFormat object to format output.
DecimalFormat dollar = new DecimalFormat("0.00");

// Display the charges.
JOptionPane.showMessageDialog(null, "Subtotal: $" + dollar.format(subtotal) + " ");
/**
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);
}
}
}

===================================================================================

The final class which calls the all the clasess to display out the result or the output.

/**
This program creates an instance of the Chp07PC06 class
which displays the GUI for the Automotive workshop.
*/

public class Fclass
{
public static void main(String[] args)
{
new Chp07PC06();
}
}

The code above shown has the functionality as per asked in the question.