Question: What's wrong with my java? I can't solve the errors. import java.awt.FlowLayout; import java.awt.Font; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; import

What's wrong with my java? I can't solve the errors.

import java.awt.FlowLayout;

import java.awt.Font;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JButton;

import javax.swing.JTextField;

import javax.swing.ButtonGroup;

import javax.swing.JRadioButton;

import javax.swing.JTextArea;

import javax.swing.JOptionPane;

import javax.swing.JScrollPane;

public class RockyWoodfiredPizzasGUI extends JFrame implements ActionListener

{

private final int MAX_PIZZAS = 10;

private Pizza [] pizzaArray = new Pizza[MAX_PIZZAS];

private int currentPizza = 0;

private JLabel titleLabel = new JLabel("Rocky Woodfired Pizzas Management System"); // program title

private JLabel nameLabel = new JLabel("Customer name: ");// for prompt

private JTextField nameField = new JTextField(28);// for name entry

private ButtonGroup sizeGroup = new ButtonGroup();

private JRadioButton smallButton = new JRadioButton("Small");

private JRadioButton mediumButton = new JRadioButton("Medium");

private JRadioButton largeButton = new JRadioButton("Large");

private JRadioButton hiddenButton = new JRadioButton("Hidden");

public RockyWoodfiredPizzasGUI();

private JLabel toppingsLabel = new JLabel("Number of toppings: ");// for prompt

private JTextField toppingsField = new JTextField(4);// for number of guests entry

private JTextArea displayTextArea = new JTextArea("", 16, 60); // declare text area

private JScrollPane scrollPane; // scroll pane for the text area

//declare all of the buttons

private JButton enterButton = new JButton("Enter"); // buttons

private JButton displayButton = new JButton("Display All");

private JButton searchButton = new JButton("Search");

private JButton exitButton = new JButton("Exit");

public RockyWoodfiredPizzasGUI()

{ // constructor create the Gui

this.setLayout(new FlowLayout());// set JFrame to FlowLayout

titleLabel.setFont(new Font("Ariel", Font.BOLD, 22));

add(titleLabel);

add(nameLabel);

add(nameField);

add(toppingsLabel);

add(toppingsField);

sizeGroup.add(smallButton);

sizeGroup.add(mediumButton);

sizeGroup.add(largeButton);

sizeGroup.add(hiddenButton);

hiddenButton.setSelected(true);

add(smallButton);

add(mediumButton);

add(largeButton);

// set text area to a monospaced font so the columns can be aligned using a format string

displayTextArea.setFont(new Font("Monospaced", Font.PLAIN, 12));

displayTextArea.setEditable(false);// make text area read only

scrollPane = new JScrollPane(displayTextArea);// add text area to the scroll pane

scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); // just need vertical scrolling

add(scrollPane);

add(enterButton);

add(displayButton);

add(searchButton);

add(exitButton);

enterButton.addActionListener(this);// add the action listener to the buttons

displayButton.addActionListener(this);

searchButton.addActionListener(this);

exitButton.addActionListener(this);

// when the user pushes the system close (X top right corner)

addWindowListener( // override window closing method

new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

exit();// Attempt to exit application

}

}

);

}

public void actionPerformed(ActionEvent e)

{ // process the clicks on all of the buttons

String command = e.getActionCommand();

if (command.compareTo("Enter") == 0)

enter();

else if (command.compareTo("Display All") == 0)

displayAll();

else if (command.compareTo("Search") == 0)

search();

else if (command.compareTo("Exit") == 0)

exit();

}

private void enter()

{

// TODO -- Read in customer name and number of toppings and size of pizza information and add to the pizza array

String customerName = nameField.getText();

int toppings = Integer.parseInt(toppingsField.getText());

pizzaArray[currentPizza] = new Pizza(customerName, pizzaSize, toppings);

displayHeading();

// TODO -- Display customer name, pizza size, number of toppings and the pizza charge to the text area

displayTextArea.setText(String.format("%-30s%-7s%-15s%-6s ","Customer Name", "Size", "Toppings", "Charge"));

pizzaArray[currentPizza].getCustomerName();

pizzaArray[currentPizza].getSize();

pizzaArray[currentPizza].getToppings();

pizzaArray[currentPizza].calculateCharge();

}

// TODO -- Clear input fields, select hidden radio button and return focus to the customer name field and increment current pizza variable

private void order ()

{

nameField.setText("");

toppingsField.setText("");

smallButton.requestFocus();

currentPizza++;

if (smallButton.isSelected())

pizzaSize = "Small";

else if (mediumButton.isSelected())

pizzaSize = "Medium";

else if (largeButton.isSelected())

pizzaSize = "Large";

if (hiddenButton.isSelected())

displayTextArea.setText("");

displayTextArea.append("You must enter a size");

return;

}

// TODO -- complete error message code (put this code at the beginning of the method)

{

if(currentPizza == MAX_PIZZAS)

{

JOptionPane.showMessageDialog(rootPane, "Maximum number of pizzas has been reached", "Rocky Woodfired Pizzas Management System", JOptionPane.ERROR_MESSAGE);

return;

}

if(customerName.getText().compareTo("") == 0)

{

JOptionPane.showMessageDialog(rootPane, "You must enter a customer name", "Rocky Woodfired Pizzas Management System", JOptionPane.ERROR_MESSAGE);

customerName.requestFocus();

return;

}

if (nameField.getText().compareTo("") == 0)

{

JOptionPane.showMessageDialog(rootPane, "You must enter a search name", "Rocky Woodfired Pizzas Management System", JOptionPane.ERROR_MESSAGE);

nameField.requestFocus();

return;

}

}

private void displayHeading()

{

displayTextArea.setText(String.format("%-30s%-7s%-15s%-6s ", "Customer Name", "Size", "Toppings", "Charge"));

appendLine();

}

private void appendLine()

{

displayTextArea.append("----------------------------------------------------------- ");

}

private void displayAll()

{

// TODO -- display all of the entries entered so far

for(int i=0; i

{

totalCollectedCharges += pizzaArray[i].calculateCharge();

totalNumberOfCustomer += pizzaArray[i].getCustomerName();

displayTextArea.append(String.format("%-30s%-17s$%5.2f ",

pizzaArray[i].getCustomerName(),

pizzaArray[i].calculateCharge()));

appendLine();

double averagePizza=((totalNumberOfPizza*1.0)/currentPizza);

}

// TODO -- display average toppings per pizza and total charges collected

{

displayTextArea.append(String.format("%s: %5.2f ","Average toppings per pizza",averageToppings));

displayTextArea.append(String.format("%s: $%5.2f ","Total charges",totalCollectedCharges));

// TODO -- complete error message code (put at the beginning of the method)

}

}

private void search()

{

// TODO -- read search key (customer name) from input dialog

String customerName= JOptionPane.showInputDialog(rootPane, "Enter a customer name to search", "Search",JOptionPane.OK_CANCEL_OPTION);

// TODO -- iterate through array to search for the search key

boolean found=false;

displayHeading();

for(int i=0;i

{

if(pizzaArray[i].getCustomerName().equalsIgnoreCase(searchCustomer))

found=true;

}

// TODO -- display the entry if it exists or an error message if it doesn't

displayTextArea.append(String.format("%-30s%-17s$%5.2f ",pizzaArray[i].getCustomerName(),

pizzaArray[i].getCustomerName(),

pizzaArray[i].calculateCharge()));

// TODO -- complete error message code (put at the beginning of the method)

if(!found)

{

displayTextArea.setText("");

JOptionPane.showMessageDialog(rootPane, customerName + " not found", "Rocky Woodfired Pizzas Management System", JOptionPane.ERROR_MESSAGE);

}

}

private void exit()

{

// TODO -- display exit message here

JOptionPane.showMessageDialog(rootPane, "Thank you for using the Rocky Woodfired Pizzas Management System", "Rocky Woodfired Pizzas Management System",JOptionPane.OK_OPTION);

System.exit(0);

} // exit

// Main method create instance of class

public static void main(String[] args)

{

RockyWoodfiredPizzasGUI f = new RockyWoodfiredPizzasGUI();// Create instance of class

f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);// allow the code to close the program

f.setBounds(200, 100, 480, 440);// Define position and size of app

f.setTitle("Rocky Woodfired Pizza Management System");// Set the title of the app

f.setVisible(true);// Make the application visible

f.setResizable(false);// Make the window not resizable

} // main

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!