Theater Revenue A movie theater only keeps a percentage of the revenue earned fr
ID: 3827974 • Letter: T
Question
Theater Revenue
A movie theater only keeps a percentage of the revenue earned from ticket sales. The remainder
goes to the movie company. Create a GUI application that allows the user to enter the following data into text fields:
Price per adult ticket
Number of adult tickets sold
Price per child ticket
Number of child tickets sold
The application should calculate and display the following data for one night’s box office business at a theater:
Gross revenue for adult tickets sold. This is the amount of money taken in for all adult tickets sold.
Net revenue for adult tickets sold. This is the amount of money from adult ticket sales left over after the payment to the movie company has been deducted.
Gross revenue for child tickets sold. This is the amount of money taken in for all child tickets sold.
Net revenue for child tickets sold. This is the amount of money from child ticket sales left over after the payment to the movie company has been deducted.
Total gross revenue. This is the sum of gross revenue for adult and child tickets sold.
Total net revenue. This is the sum of net revenue for adult and child tickets sold.
Assume the theater keeps 20 percent of its box office receipts. Use a constant in your code to represent this percentage.
theater.java
import javax.swing.*;
import java.awt.event.*;
public class theater extends JFrame
{
private final int WINDOW_WIDTH = 500;
private final int WINDOW_HEIGHT = 500;
private final double THEATER = .20;
private JPanel panel;
private JButton calculate;
private JTextField Children;
private JTextField Adult;
private JTextField children;
private JTextField adult;
private JLabel c;
private JLabel c1;
private JLabel a;
private JLabel a1;
public theater()
{
setTitle("Movie Theater Application");
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildPanel();
add(panel);
pack();
setVisible(true);
}
public void buildPanel()
{
panel = new JPanel();
c = new JLabel("How many Children are attending the show?");
children = new JTextField(3);
c1 = new JLabel("How much is it for one child ticket?");
Children = new JTextField(5);
a1 = new JLabel("How much is it for one adult ticket?");
Adult = new JTextField(5);
a = new JLabel("How many Adults are attending the show?");
adult = new JTextField(3);
calculate = new JButton("Calculate");
calculate.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
String c1 = Children.getText();
double CHILD = Double.parseDouble(c1);
String a1 = Adult.getText();
double ADULT = Double.parseDouble(a1);
String ch = children.getText();
String ad = adult.getText();
int chi = Integer.parseInt(ch);
int adu = Integer.parseInt(ad);
double chigross = chi * CHILD;
double adugross = adu * ADULT;
double gross = chigross + adugross;
double chinet = chigross * THEATER;
double adunet = adugross * THEATER;
double net = chinet + adunet;
JOptionPane.showMessageDialog(null, gross);
}
});
panel.add(c);
panel.add(children);
panel.add(c1);
panel.add(Children);
panel.add(a);
panel.add(adult);
panel.add(a1);
panel.add(Adult);
panel.add(calculate);
}
public static void main(String args[])
{
new theater();
}
}
Explanation / Answer
import javax.swing.*;
import java.awt.event.*;
public class theater extends JFrame
{
private final int WINDOW_WIDTH = 500;
private final int WINDOW_HEIGHT = 500;
private final double THEATER = .20;
private JPanel panel;
private JButton calculate;
private JTextField Children;
private JTextField Adult;
private JTextField children;
private JTextField adult;
private JLabel c;
private JLabel c1;
private JLabel a;
private JLabel a1;
public theater()
{
setTitle("Movie Theater Application");
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildPanel();
add(panel);
pack();
setVisible(true);
}
public void buildPanel()
{
panel = new JPanel();
c = new JLabel("How many Children are attending the show?");
children = new JTextField(3);
c1 = new JLabel("How much is it for one child ticket?");
Children = new JTextField(5);
a1 = new JLabel("How much is it for one adult ticket?");
Adult = new JTextField(5);
a = new JLabel("How many Adults are attending the show?");
adult = new JTextField(3);
calculate = new JButton("Calculate");
calculate.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
String c1 = Children.getText();
double CHILD = Double.parseDouble(c1);
String a1 = Adult.getText();
double ADULT = Double.parseDouble(a1);
String ch = children.getText();
String ad = adult.getText();
int chi = Integer.parseInt(ch);
int adu = Integer.parseInt(ad);
double chigross = chi * CHILD;
double adugross = adu * ADULT;
double gross = chigross + adugross;
double chinet = chigross * THEATER;
double adunet = adugross * THEATER;
double net = chinet + adunet;
JOptionPane.showMessageDialog(null, gross);
}
});
panel.add(c);
panel.add(children);
panel.add(c1);
panel.add(Children);
panel.add(a);
panel.add(adult);
panel.add(a1);
panel.add(Adult);
panel.add(calculate);
}
public static void main(String args[])
{
new theater();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.