1.) Modify the Brandi\'s Bagel House Application to capture all the items sold f
ID: 3771830 • Letter: 1
Question
1.) Modify the Brandi's Bagel House Application to capture all the items sold for each transaction. You will create an EDI 850 outfile transaction segment for each transaction. You must process and create 3 different 850 transaction segments (from the ST to the SE code for each) within your file. This means that you will have 3 different orders within the 1 outfile, each having their own set of transaction codes.
2.) Create a Java application to report the total number of Items sold for each item on the menu. You will create a driver and an additional class file that will read the EDI 850 outfile created in step 1. You need the data from the PO1 segment. The program will read the 850 outfile and report the totals to the console.
Here is my part of code i can't figure how to modify:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
/**
The OrderCalculatorGUI class creates the GUI for the
Brandi's Bagel House application.
*/
public class OrderCalculatorGUI extends JFrame
{
private BagelPanel bagels; // Bagel panel
private ToppingPanel toppings; // Topping panel
private CoffeePanel coffee; // Coffee panel
private GreetingPanel banner; // To display a greeting
private JPanel buttonPanel; // To hold the buttons
private JButton calcButton; // To calculate the cost
private JButton exitButton; // To exit the application
private final double TAX_RATE = 0.06; // Sales tax rate
/**
Constructor
*/
public OrderCalculatorGUI()
{
// Display a title.
setTitle("Order Calculator");
// Specify an action for the close button.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create a BorderLayout manager.
setLayout(new BorderLayout());
// Create the custom panels.
banner = new GreetingPanel();
bagels = new BagelPanel();
toppings = new ToppingPanel();
coffee = new CoffeePanel();
// Create the button panel.
buildButtonPanel();
// Add the components to the content pane.
add(banner, BorderLayout.NORTH);
add(bagels, BorderLayout.WEST);
add(toppings, BorderLayout.CENTER);
add(coffee, BorderLayout.EAST);
add(buttonPanel, BorderLayout.SOUTH);
// Pack the contents of the window and display it.
pack();
setVisible(true);
}
/**
The buildButtonPanel method builds the button panel.
*/
private void buildButtonPanel()
{
// Create a panel for the buttons.
buttonPanel = new JPanel();
// Create the buttons.
calcButton = new JButton("Calculate");
exitButton = new JButton("Exit");
// Register the action listeners.
calcButton.addActionListener(new CalcButtonListener());
exitButton.addActionListener(new ExitButtonListener());
// Add the buttons to the button panel.
buttonPanel.add(calcButton);
buttonPanel.add(exitButton);
}
/**
Private inner class that handles the event when
the user clicks the Calculate button.
*/
private class CalcButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
// Variables to hold the subtotal, tax, and total
double subtotal, tax, total;
// Calculate the subtotal.
subtotal = bagels.getBagelCost() +
toppings.getToppingCost() +
coffee.getCoffeeCost();
// Calculate the sales tax.
tax = subtotal * TAX_RATE;
// Calculate the total.
total = subtotal + tax;
// Create a DecimalFormat object to format output.
DecimalFormat dollar = new DecimalFormat("0.00");
// Display the charges.
JOptionPane.showMessageDialog(null, "Subtotal: $" +
dollar.format(subtotal) + " " +
"Tax: $" + dollar.format(tax) + " " +
"Total: $" + dollar.format(total));
}
}
/**
Private inner class that handles the event when
the user clicks the Exit button.
*/
private class ExitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
/**
main method
*/
public static void main(String[] args)
{
new OrderCalculatorGUI();
}
}
import java.awt.*;
import javax.swing.*;
/**
* The BagelPanel class allows the user to select either
* a white or whole wheat bagel.
*/
public class BagelPanel extends JPanel
{
// The following constants are used to indicate
// the cost of each type of bagel.
public final double WHITE_BAGEL = 1.25;
public final double WHEAT_BAGEL = 1.50;
public final double CINNAMON_BAGEL= 2.00;
// The following variables will reference radio
// buttons for white and whole wheat bagels.
private JRadioButton whiteBagel;
private JRadioButton wheatBagel;
private JRadioButton CinammonBagel;
// The following variable will reference a
// ButtonGroup object to group the radio buttons.
private ButtonGroup bg;
/**
* Constructor
*/
public BagelPanel()
{
// Create a GridLayout manager with
// two rows and one column.
setLayout(new GridLayout(3, 1));
// Create the radio buttons.
whiteBagel = new JRadioButton("White", true);
wheatBagel = new JRadioButton("Wheat");
CinammonBagel = new JRadioButton("Cinammon Crunch");
// Group the radio buttons.
bg = new ButtonGroup();
bg.add(whiteBagel);
bg.add(wheatBagel);
bg.add(CinammonBagel);
// Add a border around the panel.
setBorder(BorderFactory.createTitledBorder("Bagel"));
// Add the radio buttons to this panel.
add(whiteBagel);
add(wheatBagel);
add(CinammonBagel);
}
/**
* The getBagelCost method returns the cost of
* the selected bagel.
*/
public double getBagelCost()
{
// The following variable will hold the cost
// of the selected bagel.
double bagelCost = 0.0;
// Determine which bagel is selected.
if (whiteBagel.isSelected())
bagelCost = WHITE_BAGEL;
else
bagelCost = WHEAT_BAGEL;
else
bagelCost = CinammonBagel;
// Return the cost of the selected bagel.
return bagelCost;
}
}
Explanation / Answer
public class Bagel
{
public static void main(String[] args)
{
new OrderCalculatorGUI();
}
}
import javax.swing.*;
import java.awt.*;
public class BagelPanel extends JPanel
{
public final double WHITE_BAGEL = 1.25;
public final double WHEAT_BAGEL= 1.50;
private JRadioButton whiteBagel; // to select white
private JRadioButton wheatBagel; // to select wheat
private ButtonGroup bg; // to group the buttons
public BagelPanel()
setLayout(new GridLayout(2, 1));
whiteBagel = new JRadioButton("White", true);
wheatBagel = new JRadioButton("Wheat");
bg = new ButtonGroup();
bg.add(whiteBagel);
bg.add(wheatBagel);
setBorder(BorderFactory.createTitledBorder("Bagel"));
add(whiteBagel);
add(wheatBagel);
}
public double getBagelCost()
{
double bagelCost = 0.0;
if (whiteBagel.isSelected())
bagelCost = WHITE_BAGEL;
else
bagelCost = WHEAT_BAGEL;
return bagelCost;
}
}
import javax.swing.*;
import java.awt.*;
public class CoffeePanel extends JPanel
{
public final double NO_COFFEE = 0.0;
public final double REGULAR_COFFEE = 1.25;
public final double DECAF_COFFEE = 1.25;
public final double CAPPUCCINO = 2.00;
private JRadioButton noCoffee;
private JRadioButton regularCoffee;
private JRadioButton decafCoffee;
private JRadioButton cappuccino;
private ButtonGroup bg;
public CoffeePanel()
{
setLayout(new GridLayout(4, 1));
noCoffee = new JRadioButton("None");
regularCoffee = new JRadioButton("Regular coffee", true);
decafCoffee = new JRadioButton("Decaf coffee");
cappuccino = new JRadioButton("Cappuccino");
setBorder(BorderFactory.createTitledBorder("Coffee"));
bg = new ButtonGroup();
bg.add(noCoffee);
bg.add(regularCoffee);
bg.add(decafCoffee);
bg.add(cappuccino);
add(noCoffee);
add(regularCoffee);
add(decafCoffee);
add(cappuccino);
}
public double getCoffeeCost()
{
double coffeeCost = 0.0;
if (noCoffee.isSelected())
coffeeCost = NO_COFFEE;
else if (regularCoffee.isSelected())
coffeeCost = REGULAR_COFFEE;
else if (decafCoffee.isSelected())
coffeeCost = DECAF_COFFEE;
else if (cappuccino.isSelected())
coffeeCost = CAPPUCCINO;
return coffeeCost;
}
}
import javax.swing.*;
public class GreetingPanel extends JPanel
{
private JLabel greeting;
public GreetingPanel()
{
greeting = new JLabel("Welcome to Papa Smurf's Bagel House");
add(greeting);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
// The OrderCalculatorGUI class creates the GUI for the
// Papa Smurf's Bagel House
public class OrderCalculatorGUI extends JFrame
{
private BagelPanel bagels; // Bagel panel
private ToppingPanel toppings; // Toppings
private CoffeePanel coffee; // Coffee panel
private GreetingPanel banner; // to display a greeting
private JPanel buttonPanel; // to hold the buttons
private JButton calcButton; // to calculate the cost
private JButton exitButton; // to exit the application
private final double TAX_RATE = 0.07; // sales tax
// the constructor
public OrderCalculatorGUI()
{
// display a title
setTitle("Order Calculator");
// specify the action for the close button
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// create a BorderLayout manager
setLayout(new BorderLayout());
// create the custom panels
banner = new GreetingPanel();
bagels = new BagelPanel();
toppings = new ToppingPanel();
coffee = new CoffeePanel();
// create the button panel
buildButtonPanel();
// add the components to the content pane
add(banner, BorderLayout.NORTH);
add(bagels, BorderLayout.WEST);
add(coffee, BorderLayout.EAST);
add(buttonPanel, BorderLayout.SOUTH);
add(toppings, BorderLayout.CENTER);
// pack the contents of the window and display it
pack();
setVisible(true);
}
// BuildButtonPanel builds the button panel
private void buildButtonPanel()
{
// crete a panel for the buttons
buttonPanel = new JPanel();
// create the buttons
calcButton = new JButton("Calculate");
exitButton = new JButton("Exit");
// register the action listeners
calcButton.addActionListener(new CalcButtonListener());
exitButton.addActionListener(new ExitButtonListener());
// add the buttons to the button panel
buttonPanel.add(calcButton);
buttonPanel.add(exitButton);
}
// private innere class that handles the event when the user
// clicks the Calculate button
private class CalcButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
// variables to hold subtotal, tax, and total
double subtotal, tax, total;
// calculate the subtotal
subtotal = bagels.getBagelCost() +
toppings.getToppingCost() +
coffee.getCoffeeCost();
// calculate the sales tax
tax = subtotal * TAX_RATE;
// calculate the total
total = subtotal + tax;
// create a DecimalFormat to format output
DecimalFormat dollar = new DecimalFormat("0.00");
// display the charges
JOptionPane.showMessageDialog(null, "Subtotal: $" +
dollar.format(subtotal) + " " +
"Tax: $" + dollar.format(tax) + " " +
"Total: $" + dollar.format(total));
}
}
// private inner class that handles the event when the user
// clicks the Exit button
private class ExitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
}
6. The ToppingPanel Class
-------------------------
import javax.swing.*;
import java.awt.*;
// the topings panel allows you to select a toping for the bagel
public class ToppingPanel extends JPanel
{
// the constants indicate the cost of toppings
public final double CREAM_CHEESE = 0.50;
public final double BUTTER = 0.25;
public final double PEACH_JELLY =0.75;
public final double BLUEBERRY_JAM = 0.75;
private JCheckBox creamCheese; // to select cream cheese
private JCheckBox butter; // to select butter
private JCheckBox peachJelly; // to select peach jelly
private JCheckBox blueberryJam; // to select blueberry jam
// the constructor
public ToppingPanel()
{
// create a GridLayout manager with
// 4 rows and 1 column
setLayout(new GridLayout(4, 1));
// create the check boxes
creamCheese = new JCheckBox("Cream cheese");
butter = new JCheckBox("Butter");
peachJelly = new JCheckBox("Peach Jelly");
blueberryJam = new JCheckBox("Blueberry Jam");
// add a border around the panel
setBorder(BorderFactory.createTitledBorder("Toppings"));
// add the boxes to the panel
add(creamCheese);
add(butter);
add(peachJelly);
add(blueberryJam);
}
public double getToppingCost()
{
double toppingCost = 0.0;
if (creamCheese.isSelected())
toppingCost += CREAM_CHEESE;
if (butter.isSelected())
toppingCost += BUTTER;
if (peachJelly.isSelected())
toppingCost += PEACH_JELLY;
if (blueberryJam.isSelected())
toppingCost += BLUEBERRY_JAM;
return toppingCost;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.