Question

Project overview: Create a java graphics program that displays an order menu and bill from a Sandwich shop, or any other esta
Project Requirements: NOTE: USE OF A GUI BUILDER (DRAG AND DROP COMPONENTS) IS NOT ALLOWED. 1. Develop a project that provide
Implementation Notes: 1. Create a project that is object oriented, therefore there should be several classes. 2. Each student
4. Below is an outline of possible structure of the program. This is a basic outline and does not address all the required de
0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOurceCode:

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

public class MyFrame {
  
public static void main(String[] args) {

JFrame frame = new JFrame("Order Calculator");

frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  
JPanel panel = new JPanel();

frame.add(panel);

placeComponents(panel);


frame.setVisible(true);
}

private static void placeComponents(JPanel panel) {

String bread;String coffee; boolean cheese=false,ham=false,turkey=false,beef=false;
panel.setLayout(null);
JLabel welcomeLabel = new JLabel("Welcome to Johnny's Sandwich Shop");
welcomeLabel.setBounds(20,0,300,20);
panel.add(welcomeLabel);
  
JLabel breadLabel = new JLabel("bread");
breadLabel.setBounds(10,21,100,20);
panel.add(breadLabel);
  
       JRadioButton option1 = new JRadioButton("White");
JRadioButton option2 = new JRadioButton("Wheat");

ButtonGroup group = new ButtonGroup();
group.add(option1);
group.add(option2);

  
option1.setBounds(10,41,100,20);
panel.add(option1);
option1.setSelected(true);
option2.setBounds(110,41,100,20);
panel.add(option2);

if(option1.isSelected())
   bread="white";
else
   bread="wheat";
  
JLabel meatLabel = new JLabel("meat/cheese");
meatLabel.setBounds(10,81,100,20);
panel.add(meatLabel);

JCheckBox cheesecheckbox = new JCheckBox("Cheese", true);
JCheckBox beefcheckbox = new JCheckBox("Beef", false);
JCheckBox turkeycheckbox = new JCheckBox("Turkey", false);
JCheckBox hamcheckbox = new JCheckBox("Ham",false);

cheesecheckbox.setBounds(10,101,100,20);
panel.add(cheesecheckbox);
beefcheckbox.setBounds(110,101,100,20);
panel.add(beefcheckbox);
turkeycheckbox.setBounds(210,101,100,20);
panel.add(turkeycheckbox);
hamcheckbox.setBounds(310,101,100,20);
panel.add(hamcheckbox);

JLabel coffeeLabel = new JLabel("coffee");
coffeeLabel.setBounds(10,121,100,20);
panel.add(coffeeLabel);
  
if(cheesecheckbox.isSelected())
   cheese=true;
  
if(beefcheckbox.isSelected())
   cheese=true;
  
if(turkeycheckbox.isSelected())
   cheese=true;
  
if(hamcheckbox.isSelected())
   cheese=true;
  
JRadioButton option21 = new JRadioButton("None");
JRadioButton option22 = new JRadioButton("Regular");
JRadioButton option23 = new JRadioButton("Decaf");
JRadioButton option24 = new JRadioButton("Cappuchino");

ButtonGroup group1 = new ButtonGroup();
group1.add(option21);
group1.add(option22);
group1.add(option23);
group1.add(option24);

  
option21.setBounds(10,141,100,20);
panel.add(option21);
option21.setSelected(true);
option22.setBounds(110,141,100,20);
panel.add(option22);
option23.setBounds(210,141,100,20);
panel.add(option23);
option24.setBounds(310,141,100,20);
panel.add(option24);
  
if(option21.isSelected())
   coffee="none";
else if(option22.isSelected())
   coffee="regular";
else if(option23.isSelected())
   coffee="decaf";
else
   coffee="cappuchino";
  
JButton close = new JButton("Close");
close.addActionListener(new CloseListener());
close.setBounds(10,181,100,20);
panel.add(close);
  
JButton calculate = new JButton("Calculate");
calculate.addActionListener(new CalculateListener(bread,coffee,cheese,beef,turkey,ham));
calculate.setBounds(110,181,100,20);
panel.add(calculate);
          

}

}
---------------------------------------------------------------------------------------------------------------------
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class CalculateListener implements ActionListener{

   private double subtotal;
   private double white_bread;
   private double wheat_bread;
   private double cheese;
   private double beef;
   private double turkey;
   private double ham;
  
   private double regular;
   private double capuccino;
   private double decaf;
  
   public CalculateListener(String bread, String coffee, boolean cheese2, boolean beef2, boolean turkey2, boolean ham2) {
      
       subtotal=0;
       white_bread=0.99;
       wheat_bread=0.99;
           cheese=0.50;
           beef=0.50;
       turkey=0.50;
       ham=0.50;
             
           regular=2.99;
           capuccino=3.99;
           decaf=4.99;
          
          
          
           if(bread.equals("white"))
               subtotal+=white_bread;
           else
               subtotal+=wheat_bread;
          
           if(coffee.equals("none"))
               subtotal+=0;
           else if(coffee.equals("regular"))
               subtotal+=regular;
           else if(coffee.equals("decaf"))
               subtotal+=decaf;  
           else
               subtotal+=capuccino;
          
           if(cheese2)
               subtotal+=cheese;
           if(ham2)
               subtotal+=ham;
               if(turkey2)
                   subtotal+=turkey;
          
           if(beef2)
               subtotal+=beef;
          
   }

   @Override
   public void actionPerformed(ActionEvent e) {
  
      
      
       JFrame frame = new JFrame("Bill generator");
     
   frame.setSize(500, 500);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  
   JPanel panel = new JPanel();
     
   JLabel subtotalLabel = new JLabel("Subtotal: "+subtotal+"$");
   subtotalLabel.setBounds(20,0,300,20);
   panel.add(subtotalLabel);
     
   JLabel taxLabel = new JLabel("tax: "+0.17*subtotal+"$");
   taxLabel.setBounds(20,100,300,20);
   panel.add(taxLabel);
     
   JLabel totalLabel = new JLabel("total: "+1.17*subtotal+"$");
       totalLabel.setBounds(20,200,300,20);
       panel.add(totalLabel);
  
       JButton close = new JButton("Close");
       close.addActionListener(new CloseListener());
       close.setBounds(20,300,100,20);
       panel.add(close);
     
  
   frame.add(panel);
     
   frame.setVisible(true);
     
   }
     
  
}
---------------------------------------------------------------------------------------------------------------------
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class CloseListener implements ActionListener {

   @Override
   public void actionPerformed(ActionEvent e) {
   //DO SOMETHING
   System.exit(0);
   }

}

Order Calculator - Х Welcome to Johnnys Sandwich Shop bread O White O Wheat meat cheese ✓ Cheese Beef Turkey Ham coffee O NoBill generator Х Subtotal: 1.49$ tax: 0.2533$ total: 1.7432999999999998$ Close

Add a comment
Know the answer?
Add Answer to:
Project overview: Create a java graphics program that displays an order menu and bill from a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Java, please create the program for the following prompt. MUST CREATE BUTTONS IN A JFRAME,...

    Using Java, please create the program for the following prompt. MUST CREATE BUTTONS IN A JFRAME, as specified by the prompt! DO NOT use user input of 1, 2, 3 etc. User input must come from clicking the buttons. Please be sure to test your program. Thank you! Write a program that displays three buttons with the names or images of three candidates for public of office. Imagine that a person votes by clicking the button that shows the candidate...

  • For this project your card class must include an Image of the card. Here is a...

    For this project your card class must include an Image of the card. Here is a zip filecontaining 52 images you can use for your cards. Please note that the name for each card can be created by the concatenation of the first character of the suit, the value of the card, and the ".png" suffix. When you construct a card, you should have it load its image. Alternatives exist regarding how to draw() the card. One way to do...

  • Create an order entry screen program in C# to give a total for an individual pizza...

    Create an order entry screen program in C# to give a total for an individual pizza order. The Pizza order should have radio buttons for small $7, medium $9, and large $12 choices for the pizza. There should be a checkbox for drink (where a drink is $2 added if it is checked and nothing added if it is not checked. Include a textbox for the customer’s name. Have a button to calculate the subtotal (pizza choice and whether there...

  • eclipse java Oxygen Design a self-service fast food menu. Name your class FastFood. Create a test...

    eclipse java Oxygen Design a self-service fast food menu. Name your class FastFood. Create a test class based on the examples from chapter 4. Create a program to do the following. When you set up the program, save the java file to a folder named Chapter 04 Program. Console Welcome to the fast food order menu How may I help you Please place your order: НННН Please place your order Your order Your subtotal: $e.00 $e.00 Continue? (y/n): Y Please...

  • Programming Project 3 See Dropbox for due date Project Outcomes: Develop a Java program that uses:...

    Programming Project 3 See Dropbox for due date Project Outcomes: Develop a Java program that uses: Exception handling File Processing(text) Regular Expressions Prep Readings: Absolute Java, chapters 1 - 9 and Regular Expression in Java Project Overview: Create a Java program that allows a user to pick a cell phone and cell phone package and shows the cost. Inthis program the design is left up to the programmer however good object oriented design is required.    Project Requirements Develop a text...

  • JAVA program For this project you are to create an array of objects of your choice...

    JAVA program For this project you are to create an array of objects of your choice using java your Driver Class, Object Classes should all be named appropriately depending on what Classes and Objects you decide to create for this assignment. This project must give the user the ability to view and to change the elements of the array. Print your results (output) as a clear and informative statement. Your output should also include an explanation of what your program...

  • Order up:: Write a program that will be used to keep track of orders placed at...

    Order up:: Write a program that will be used to keep track of orders placed at a donut shop. There are two types of items that can be ordered: coffee or donuts. Your program will have a class for each order type, and an abstract superclass. Coffee orders are constructed with the following information: quantity (int) - how many coffees are being ordered size (String) - the size of the coffees (all coffees in the order have the same size)...

  • Write the following program in Java using Eclipse. A cash register is used in retail stores...

    Write the following program in Java using Eclipse. A cash register is used in retail stores to help clerks enter a number of items and calculate their subtotal and total. It usually prints a receipt with all the items in some format. Design a Receipt class and Item class. In general, one receipt can contain multiple items. Here is what you should have in the Receipt class: numberOfItems: this variable will keep track of the number of items added to...

  • ___________________ Create a shell script program that has displays the following menu on a page: This...

    ___________________ Create a shell script program that has displays the following menu on a page: This is a Linux Question, and the script is written in Vi test, and run in Putty. Press 1 to enter new order. Press 2 to access order status. Press 3 to cancel order. Paste a screenshot shot of the code below Paste a screenshot of the code output below (2 point):

  • Create two classes following the model shown in Chapter 19. Assuming your data form's subject is ...

    Here's the pizza example layout.Need Help with this program. Java ser interface: Here are the groupings trom the pizza u Size Pepperoni Anchovies Smal edium Large Your Price: Create two classes following the model shown in Chapter 19. Assuming your data form's subject is X (though l expect better names), you need to provide the following classes: 1. XFormFrame, as a subclass of JFrame, responsible for creating and operating the form 2. XFormViewer, your main program responsible for creating the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT