Please write it in Java language
Below is the solution:
code:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.WindowConstants;
public class ComputerStore extends javax.swing.JFrame {
// Variables declaration - do not modify
private JButton btnCalculate;
private JButton btnExit;
private ButtonGroup buttonGroup1;
private JCheckBox chkFormatHardDrive;
private JCheckBox chkInstallHardDrive;
private JCheckBox chkInstallRam;
private JCheckBox chkQuoteHourlyLabour;
private JCheckBox chkVirusRemoval;
private JLabel jLabel1;
private JLabel jLabel2;
private JPanel jPanel1;
private JPanel jPanel2;
private JPanel jPanel3;
private JRadioButton jRadioButton1;
private JRadioButton jRadioButton2;
private JRadioButton jRadioButton3;
private JTextField txtHourLabour;
private JTextField txtPartCost;
// declare the variable for the price
private double formatHradDrive = 0;
private double installHardDrive = 0;
private double installRam = 0;
private double quoteHourlyLabour = 0;
private double virusRemoval = 0;
private double warranty = 0;
private double hourLabour = 0;
private double partCost = 0;
// End of variables declaration
public ComputerStore() {
super("LU Computer Store");
initComponents();
}
/**
* This method is called from within the constructor to
initialize the form.
* WARNING: Do NOT modify this code. The content of
this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed"
desc="Generated Code">
private void initComponents() {
buttonGroup1 = new
ButtonGroup();
jPanel1 = new JPanel();
chkInstallHardDrive = new
JCheckBox();
chkInstallRam = new
JCheckBox();
chkVirusRemoval = new
JCheckBox();
chkFormatHardDrive = new
JCheckBox();
chkQuoteHourlyLabour = new
JCheckBox();
jPanel2 = new JPanel();
jLabel1 = new JLabel();
jLabel2 = new JLabel();
txtPartCost = new
JTextField();
txtHourLabour = new
JTextField();
btnExit = new JButton();
btnCalculate = new JButton();
jPanel3 = new JPanel();
jRadioButton1 = new
JRadioButton();
jRadioButton2 = new
JRadioButton();
jRadioButton3 = new
JRadioButton();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(BorderFactory.createTitledBorder("Standard Services"));
chkInstallHardDrive.setText("Install Hard Drive ($25.00)");
chkInstallRam.setText("Install Ram ($15.00)");
chkVirusRemoval.setText("Virus Removal ($50.00)");
chkFormatHardDrive.setText("Foramat Hard Drive ($80.00)");
chkQuoteHourlyLabour.setText("Quote Hourly Labour ($10.00)");
GroupLayout jPanel1Layout = new
GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(chkInstallHardDrive).addComponent(chkInstallRam)
.addComponent(chkVirusRemoval).addComponent(chkFormatHardDrive)
.addComponent(chkQuoteHourlyLabour))
.addContainerGap(102, Short.MAX_VALUE)));
jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(chkInstallHardDrive)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(chkInstallRam)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(chkVirusRemoval)
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(chkFormatHardDrive)
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(chkQuoteHourlyLabour)
.addContainerGap(37, Short.MAX_VALUE)));
jPanel2.setBorder(BorderFactory.createTitledBorder("Hourly Service"));
jLabel1.setText("Part Cost:");
jLabel2.setText("Hour of Labour:");
GroupLayout jPanel2Layout = new
GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup().addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(jLabel1)
.addComponent(jLabel2))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED,
GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING,
false)
.addComponent(txtPartCost,
GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
.addComponent(txtHourLabour))
.addContainerGap()));
jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup().addGap(10, 10,
10)
.addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1).addComponent(txtPartCost,
GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2).addComponent(txtHourLabour,
GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE))
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
btnExit.setText("Exit");
btnExit.addActionListener(new
ActionListener() {
public void
actionPerformed(ActionEvent evt) {
btnExitActionPerformed(evt);
}
});
btnCalculate.setText("Calculate
Charge");
btnCalculate.addActionListener(new
ActionListener() {
public void
actionPerformed(ActionEvent evt) {
btnCalculateActionPerformed(evt);
}
});
jPanel3.setBorder(BorderFactory.createTitledBorder("Warranty Option"));
jRadioButton1.setText("2 Year Warranty ($50)");
jRadioButton2.setText("1 Year Warranty ($30)");
jRadioButton3.setText("Decline ($0)");
GroupLayout jPanel3Layout = new
GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(jPanel3Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup().addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(jRadioButton2).addComponent(jRadioButton1).addComponent(jRadioButton3))
.addContainerGap(GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)));
jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
GroupLayout.Alignment.TRAILING,
jPanel3Layout.createSequentialGroup().addContainerGap().addComponent(jRadioButton2)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(jRadioButton1)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(jRadioButton3)
.addContainerGap(13, Short.MAX_VALUE)));
GroupLayout layout = new
GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
.createSequentialGroup().addContainerGap()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel3,
GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addContainerGap())
.addComponent(jPanel1, GroupLayout.DEFAULT_SIZE,
GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, GroupLayout.DEFAULT_SIZE,
GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup().addComponent(btnCalculate)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED,
GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(btnExit)))));
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
.createSequentialGroup().addGap(19, 19,
19)
.addComponent(jPanel1,
GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2,
GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED,
GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel3,
GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)
.addGap(18, 18,
18).addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(btnCalculate).addComponent(btnExit))
.addGap(14, 14, 14)));
// add the button group to radio
button warranty
buttonGroup1.add(jRadioButton1);
buttonGroup1.add(jRadioButton2);
buttonGroup1.add(jRadioButton3);
// every checkbox event to set the
price for the each selected item
chkInstallHardDrive.addItemListener(new ItemListener() { // USB
check box checked event
@Override
public void
itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED)
{
installHardDrive =
25.00;
} else {
installHardDrive = 0;
}
}
});
//check for the format Hard Drive
checkbox is checked
chkFormatHardDrive.addItemListener(new ItemListener() { // USB
check box checked event
@Override
public void
itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED)
{
formatHradDrive = 80.00;
//set the price
} else {
installHardDrive = 0;
}
}
});
//check for the Install Ram
checkbox is checked
chkInstallRam.addItemListener(new
ItemListener() { // USB check box checked event
@Override
public void
itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED)
{
installRam = 15.00; //set the
price
} else {
installHardDrive = 0;
}
}
});
//check for the Quote Hourly Labour
checkbox is checked
chkQuoteHourlyLabour.addItemListener(new ItemListener() { // USB
check box checked event
@Override
public void
itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED)
{
quoteHourlyLabour = 10.00;
//set the price
} else {
installHardDrive = 0;
}
}
});
//check for the virus removal
checkbox is checked
chkVirusRemoval.addItemListener(new
ItemListener() { // USB check box checked event
@Override
public void
itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED)
{
virusRemoval = 50.00; //set
the price
} else {
installHardDrive = 0;
}
}
});
pack();
}
// calculate button event
private void btnCalculateActionPerformed(ActionEvent
evt) {
//check for the warranty
option
if(jRadioButton1.isSelected())
{
warranty = 30;
//set the price
}
else if(jRadioButton2.isSelected())
{
warranty = 50;
//set the price
}
else {
warranty = 0;
//set the price
}
//take value from inputbox
partCost =
Double.valueOf(txtPartCost.getText());
hourLabour =
Double.valueOf(txtHourLabour.getText());
//calculate the total
Double total = formatHradDrive +
installHardDrive + installRam + quoteHourlyLabour + virusRemoval +
warranty
+ (hourLabour*25) + partCost;
//show the message total
charge
JOptionPane.showMessageDialog(null,"Total Charges:
$"+String.valueOf(total));
}
// exit button event
private void btnExitActionPerformed(ActionEvent evt)
{
System.exit(0); // exit
application
}
// main method
public static void main(String args[]) {
new
ComputerStore().setVisible(true);
}
}
sample output:
Please write it in Java language 2. (Myinterface.java) The program description below was found waaaaay back...