write me a java code: The application must contain two windows
1
The first (main) window must allow to enter the order of a customer thanks to
Radiobuttons
Buttons
comboBoxes
The window must also contain labels that display the price of each menu
Example of an order
2 Small pizzas with 6 toppings + 1 Large pizza with 2 toppings + 2 juices + 2 Pop
A button must allow to add the different types of pizza if the customer wants it
as in the example above.
Once the order is finished, a Pay button opens the second window
in which the details of the order are displayed.
A total button displays the invoice with taxes (13%).
Another button Close allows you to close the second window and return to the main window in order to
window to take another order.
Here are the prices of the menu
Pizza Prices:
Small: 6.79Medium:8.29
Large: 9.49ExtraLarge10.29
Party Square: 1.20
Medium: 1.60
Extra Large: 2.30
Drinks
Pop 1.35
class SecondWindow extends JDialog {
private static final long serialVersionUID = 1L;
code
JTextArea orderDetails;
JButton totalButton;
JLabel totalPrice;
JButton closeButton;
DecimalFormat df = new DecimalFormat("#.##");
public SecondWindow() {
setTitle("Order Details");
setLocationRelativeTo(null);
setSize(400, 300);
setModal(true);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(0, 1));
orderDetails = new JTextArea();
orderDetails.setEditable(false);
panel.add(orderDetails);
totalButton = new JButton("Total");
totalButton.addActionListener(new TotalPriceListener());
panel.add(totalButton);
totalPrice = new JLabel("Total Price: ");
panel.add(totalPrice);
closeButton = new JButton("Close");
closeButton.addActionListener(e -> setVisible(false));
panel.add(closeButton);
this.add(panel);
}
private class TotalPriceListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
double price = 0;
for (int i = 0; i < MainWindow.pizzaPrices.length; i++) {
int numPizzas = (Integer) MainWindow.getInstance().pizzaSelectors.get(i).getSelectedItem();
int numToppings = (Integer) MainWindow.getInstance().toppingSelectors.get(i).getSelectedItem();
price += MainWindow.pizzaPrices[i] * numPizzas + MainWindow.toppingPrices[i] * numToppings * numPizzas;
}
int numPop = (Integer) MainWindow.getInstance().popNum.getSelectedItem();
int numJuice = (Integer) MainWindow.getInstance().juiceNum.getSelectedItem();
price += MainWindow.popPrice * numPop + MainWindow.juicePrice * numJuice;
price *= 1.13; // Add 13% tax
totalPrice.setText("Total Price: + df.format(price)");
}
}
}
There are a few issues with the code that you posted. I noticed that there are unused imports, and the getInstance() method does not exist for MainWindow. My suggestion is to use the variables in the MainWindow class directly instead of calling a non-existent method. I have updated the code below.