Use Java Programming Language Write a GUI to calculate the number of servings that a circular pizza of a certain diameter will make. The GUI will have the following appearance:   It must include the following features:  The frame title must say 'Pizza Servings Calculator'.  A grid layout will be used for the GUI.  The JLabel title of the GUI will say 'Pizza Servings Calculator' and be in red and will be placed in  grid slot 1.  A JLabel of 'Enter the size of the pizza in inches: ' will be placed in grid slot 2 followed by a JTextField where the pizza size will be entered and have a width of 4.  A JButton will be placed in grid slot 3 and will contain 'Calculate Servings'. A JLabel, initially blank, will be placed in grid slot 4. To execute the GUI, enter a pizza size in the JTextField and click the Calculate Servings button. The Calculate Servings button handler will then execute and calculate the number of servings and display it as shown in the following image:   The number of servings will be calculate using the following formula:          servings = (size / 8)**2 and displayed to two decimal places. You can use the Double.parseDouble(textField.getText() ) to get the string value from the JTextField and parse it to a double. This formula assumes that an 8 inch pie makes 1 serving. Based on the area of an 8" pie as one serving, the number of servings will vary with the ratio of the radius of the new pie to the 8" pie squared. Therefore, a 16" pie would give you a ratio of 16/8 or 2 squared which is 4 servings. Line 2 of the GUI contains two GUI components but each cell of a grid can only contain one component. This is where JPanels come in for GUI design. A JPanel is a container that simply holds other components, so we can use a JPanel as the component for line 2. We can create a JPanel by using a statement like: private JPanel line2 = new JPanel(); Then we can add components to it with statements like:     line2.add(variable that represents your JLabel for Enter the size of the pizza...); Then we can add line2 to the grid layout in slot 2. To set the layout of the frame to a 4 line grid layout, you would use a setLayout statement such as: setLayout(new GridLayout(4,1)); Once the servings have been calculated, they are displayed in the JLabel in grid slot 4 as shown. Set the size of your GUI to (350, 300). This should give it the appearance as shown above. Your class that represents the GUI should extend JFrame.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Use Java Programming Language

Write a GUI to calculate the number of servings that a circular pizza of a certain diameter will make. The GUI will have the following appearance:

 

It must include the following features:

  •  The frame title must say 'Pizza Servings Calculator'.
  •  A grid layout will be used for the GUI.
  •  The JLabel title of the GUI will say 'Pizza Servings Calculator' and be in red and will be placed in  grid slot 1.
  •  A JLabel of 'Enter the size of the pizza in inches: ' will be placed in grid slot 2 followed by a JTextField where the pizza size will be entered and have a width of 4.
  •  A JButton will be placed in grid slot 3 and will contain 'Calculate Servings'.
  • A JLabel, initially blank, will be placed in grid slot 4.

To execute the GUI, enter a pizza size in the JTextField and click the Calculate Servings button. The Calculate Servings button handler will then execute and calculate the number of servings and display it as shown in the following image:

 

The number of servings will be calculate using the following formula:

         servings = (size / 8)**2

and displayed to two decimal places. You can use the Double.parseDouble(textField.getText() ) to get the string value from the JTextField and parse it to a double. This formula assumes that an 8 inch pie makes 1 serving. Based on the area of an 8" pie as one serving, the number of servings will vary with the ratio of the radius of the new pie to the 8" pie squared. Therefore, a 16" pie would give you a ratio of 16/8 or 2 squared which is 4 servings.

Line 2 of the GUI contains two GUI components but each cell of a grid can only contain one component. This is where JPanels come in for GUI design. A JPanel is a container that simply holds other components, so we can use a JPanel as the component for line 2. We can create a JPanel by using a statement like:
private JPanel line2 = new JPanel();
Then we can add components to it with statements like:
    line2.add(variable that represents your JLabel for Enter the size of the pizza...);
Then we can add line2 to the grid layout in slot 2.

To set the layout of the frame to a 4 line grid layout, you would use a setLayout statement such as:
setLayout(new GridLayout(4,1));

Once the servings have been calculated, they are displayed in the JLabel in grid slot 4 as shown.

Set the size of your GUI to (350, 300). This should give it the appearance as shown above. Your class that represents the GUI should extend JFrame.

Pizza Servings Calculator
Pizza Servings Calculator
Enter the size of the pizza in inches: 12
1X
Calculate Servings
A 12 inch pizza will serve 2.25 people.
Transcribed Image Text:Pizza Servings Calculator Pizza Servings Calculator Enter the size of the pizza in inches: 12 1X Calculate Servings A 12 inch pizza will serve 2.25 people.
Pizza Servings Calculator
Pizza Servings Calculator
Enter the size of the pizza in inches:
Calculate Servings
D
X
Transcribed Image Text:Pizza Servings Calculator Pizza Servings Calculator Enter the size of the pizza in inches: Calculate Servings D X
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Running Time of Application
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education