Sure, here's a Java program that creates a cash register application using WindowBuilder:
```java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CashRegisterApplication extends JFrame {
private JLabel lblProduct, lblQuantity, lblDiscount, lblAmountDue, lblTotalAmount, lblDeductions, lblAmountGiven, lange;
private JTextField txtQuantity, txtAmountGiven;
private JButton btnCompute;
private JComboBox<String> cmbProduct, cmbDiscount;
private String[] products = {"Cheeseburger", "Pepsi", "Chips", "Coke", "Fries", "Sundae"};
private double[] prices = {55.00, 25.00, 35.00, 20.00, 45.00, 40.00};
public CashRegisterApplication() {
setTitle("Cash Register Application");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
lblProduct = new JLabel("Product:");
cmbProduct = new JComboBox<>(products);
lblQuantity = new JLabel("Quantity:");
txtQuantity = new JTextField(10);
lblDiscount = new JLabel("Discount:");
cmbDiscount = new JComboBox<>(new String[] {"Senior (10%)", "PWD (15%)"});
lblAmountDue = new JLabel("Amount Due:");
lblTotalAmount = new JLabel("-");
lblDeductions = new JLabel("Deductions:");
lblDeductions.setVisible(false);
lblAmountGiven = new JLabel("Amount Given:");
txtAmountGiven = new JTextField(10);
txtAmountGiven.setEnabled(false);
lange = new JLabel("Change:");
lange.setVisible(false);
btnCompute = new JButton("Compute");
btnCompute.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
computeAmount();
}
});
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(5, 5, 5, 5);
add(lblProduct, gbc);
gbc.gridx++;
add(cmbProduct, gbc);
gbc.gridx = 0;
gbc.gridy++;
add(lblQuantity, gbc);
gbc.gridx++;
add(txtQuantity, gbc);
gbc.gridx = 0;
gbc.gridy++;
add(lblDiscount, gbc);
gbc.gridx++;
add(cmbDiscount, gbc);
gbc.gridx = 0;
gbc.gridy++;
add(lblAmountDue, gbc);
gbc.gridx++;
add(lblTotalAmount, gbc);
gbc.gridx = 0;
gbc.gridy++;
add(lblDeductions, gbc);
gbc.gridx = 0;
gbc.gridy++;
add(lblAmountGiven, gbc);
gbc.gridx++;
add(txtAmountGiven, gbc);
gbc.gridx = 0;
gbc.gridy++;
add(lange, gbc);
gbc.gridx = 1;
gbc.gridy++;
add(btnCompute, gbc);
pack();
setLocationRelativeTo(null);
setResizable(false);
}
private void computeAmount() {
String selectedProduct = cmbProduct.getSelectedItem().toString();
int quantity = Integer.parseInt(txtQuantity.getText());
double price = getPrice(selectedProduct);
double amountDue = quantity * price;
double discountRate;
if (cmbDiscount.getSelectedItem().toString().equals("Senior (10%)")) {
discountRate = 0.10;
} else {
discountRate = 0.15;
}
double deductions = amountDue * discountRate;
double serviceCharge = amountDue * 0.02;
double totalAmount = amountDue + serviceCharge;
String amountDueStr = String.format("%.2f", amountDue);
String totalAmountStr = String.format("%.2f", totalAmount);
String deductionsStr = String.format("%.2f", deductions);
lblTotalAmount.setText(amountDueStr);
lblTotalAmount.setVisible(true);
lblDeductions.setText("Deductions: - " + deductionsStr);
lblDeductions.setVisible(true);
txtAmountGiven.setEnabled(true);
txtAmountGiven.requestFocus();
txtAmountGiven.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
double amountGiven = Double.parseDouble(txtAmountGiven.getText());
double change = amountGiven - totalAmount;
String changeStr = String.format("%.2f", change);
lange.setText("Change: " + changeStr);
lange.setVisible(true);
}
});
}
private double getPrice(String product) {
for (int i = 0; i < products.length; i++) {
if (products[i].equals(product)) {
return prices[i];
}
}
return 0.00;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new CashRegisterApplication().setVisible(true);
}
});
}
}
```
To run this program, make sure you have the WindowBuilder plugin installed in your Eclipse IDE. You can copy and paste the above code into a new Java project, then run it to launch the Cash Register Application window. You can select a product, enter the quantity, choose a discount, and click the "Compute" button to calculate the amount due. The deductions (discount), total amount, and change will be displayed accordingly.
Please note that this program assumes valid input from the user (e.g., numerical quantity, valid discount selection, etc.). Error handling and validation can be added as per your requirements.