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
  • 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...

  • 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...

  • 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...

  • 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...

  • Java Project In Brief... For this Java project, you will create a Java program for a...

    Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....

  • 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)...

  • Java Painter Class This is the class that will contain main. Main will create a new...

    Java Painter Class This is the class that will contain main. Main will create a new Painter object - and this is the only thing it will do. Most of the work is done in Painter’s constructor. The Painter class should extend JFrame in its constructor.  Recall that you will want to set its size and the default close operation. You will also want to create an overall holder JPanel to add the various components to. It is this JPanel that...

  • Needing help compiling this project Write a Java program the displays the State bird and flower....

    Needing help compiling this project Write a Java program the displays the State bird and flower. You should use your IDE for this exercise. You should also use Java classes to their full extent to include multiple methods and at least two classes. The program should prompt the user to enter a State and print both the State bird and flower. The user should be able to enter a State without worrying about case. (e.g. Users could enter Maryland, maryland,...

  • Write java program The purpose of this assignment is to practice OOP with Array and Arraylist,...

    Write java program The purpose of this assignment is to practice OOP with Array and Arraylist, Class design, Interfaces and Polymorphism. Create a NetBeans project named HW3_Yourld. Develop classes for the required solutions. Important: Apply good programming practices Use meaningful variable and constant names. Provide comment describing your program purpose and major steps of your solution. Show your name, university id and section number as a comment at the start of each class. Submit to Moodle a compressed folder of...

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
ADVERTISEMENT