Question

please using java.awt.* and javax.swing.*!!!!! Write a graphical application that produces a restaurant bill. Provide buttons...

please using java.awt.* and javax.swing.*!!!!!

Write a graphical application that produces a restaurant bill. Provide buttons for ten popular dishes or drink items. (You decide on the items and their prices.) Provide text fields for entering less popular items and prices. In a text area, show the bill, including tax and a suggested tip.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

JAVA code for the given problem: package resturant //import the required packages import java.awt.BorderLayout; ort javax.prifor JButton button: ItemsAvailbale button.addActionListener (this); add (button) foodItemnew JLabel (Extra Items) add (foodcase Beer $50.00: cost +50; break; case Coffee-$20.00: cost += 20; break; case VegRoll$30. 00 cost += 30; break; case PFrenchFries $10.00 ChickenWings $15.00 Beer $50.00 Coffee- $20.00 VegRoll -$30.00 Pizza $10.00 Burger $15.00 ColdCoffee $12.0

Raw Paste Code:

package resturant;
//import the required packages
import java.awt.BorderLayout;
import javax.print.attribute.standard.MediaSize.Other;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JFrame;
import javax.swing.JTextArea;

//The class to define the billing app
public class Restaurant extends JFrame implements ActionListener {

   private JButton[] ItemsAvailbale;
   private JTextField itemMenu, itemPrice, billAmoun;
   private JButton estimateBill;
   private JLabel foodItem, price, priceOver, mytip, tipEst;
   private JTextArea showBill;

   private double cost;

   public Restaurant() {
       initialize();
   }

   private void initialize() {
       cost = 0;
       ItemsAvailbale = new JButton[10];
       ItemsAvailbale[0] = new JButton("FrenchFries - $10.00");
       ItemsAvailbale[1] = new JButton("ChickenWings - $15.00");
       ItemsAvailbale[2] = new JButton("Beer - $50.00");
       ItemsAvailbale[3] = new JButton("Coffee- $20.00");
       ItemsAvailbale[4] = new JButton("VegRoll - $30.00");
       ItemsAvailbale[5] = new JButton("Pizza - $10.00");
       ItemsAvailbale[6] = new JButton("Burger - $15.00");
       ItemsAvailbale[7] = new JButton("ColdCoffee - $12.00");
       ItemsAvailbale[8] = new JButton("Coke - $10.00");
       ItemsAvailbale[9] = new JButton("HotDog - $20.00");
       setLayout(new GridLayout(10, 2));
    
       for (JButton button: ItemsAvailbale) {
           button.addActionListener(this);
           add(button);
       }
       foodItem = new JLabel("Extra Items");
       add(foodItem);
       price = new JLabel("Price");
       add(price);
       itemMenu = new JTextField();
       add(itemMenu);
       itemPrice = new JTextField();
       add(itemPrice);
       priceOver = new JLabel("Total cost = ");
       add(priceOver);
       billAmoun = new JTextField();
       add(billAmoun);
       mytip = new JLabel("Recommended tip");
       add(mytip);
       tipEst = new JLabel();
       add(tipEst);
       estimateBill = new JButton("Calculate cost");
       add(estimateBill);
       estimateBill.addActionListener(this);
   }

   @Override
   public void actionPerformed(ActionEvent e) {
       switch(e.getActionCommand()) {
       case "Calculate cost":
           String s = itemPrice.getText();
           if (s.length() > 0) {
               double additionalCost = Double.parseDouble(s);
               cost += additionalCost;
            
           }
           billAmoun.setText(cost + "");
           tipEst.setText(cost*0.2 + "");
           break;
        
       case "FrenchFries - $10.00":
           cost += 10;
           break;
        
       case "ChickenWings - $15.00":
           cost += 15;
           break;
        
       case "Beer - $50.00":
           cost += 50;
           break;
        
       case "Coffee - $20.00":
           cost += 20;
           break;
        
       case "VegRoll - $30.00":
           cost += 30;
           break;
        
       case "Pizza - $10.00":
           cost += 10;
           break;
        
       case "Burger - $15.00":
           cost += 15;
           break;

       case "ColdCoffee - $12.00":
           cost += 12;
           break;
        
       case "Coke - $10.00":
           cost += 10;
           break;
        
       case "HotDog - $20.00":
           cost += 20;
           break;
       }
   }

//The driver method
   public static void main(String[] args) {
       Restaurant billApp = new Restaurant();
       billApp.setDefaultCloseOperation(EXIT_ON_CLOSE);
       billApp.setSize(1000,1000);
       billApp.setVisible(true);
   }

}

Add a comment
Know the answer?
Add Answer to:
please using java.awt.* and javax.swing.*!!!!! Write a graphical application that produces a restaurant bill. Provide buttons...
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
  • Monica’s Designer Handbags: Creative Marketing Decision-Making Based on Financial Analysis—A Case Study Michael T. Manion University...

    Monica’s Designer Handbags: Creative Marketing Decision-Making Based on Financial Analysis—A Case Study Michael T. Manion University of Wisconsin – Parkside Karen Crooker University of Wisconsin – Parkside Peter Knight University of Wisconsin – Parkside Monica learned much about the designer apparel trade as an intern with a major retailer, and started a designer handbag business, selling through independent retailers. She practiced making sound marketing decisions using financial analysis techniques learned in college. These techniques proved useful when a regional discount...

  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

  • I have this case study to solve. i want to ask which type of case study...

    I have this case study to solve. i want to ask which type of case study in this like problem, evaluation or decision? if its decision then what are the criterias and all? Stardust Petroleum Sendirian Berhad: how to inculcate the pro-active safety culture? Farzana Quoquab, Nomahaza Mahadi, Taram Satiraksa Wan Abdullah and Jihad Mohammad Coming together is a beginning; keeping together is progress; working together is success. - Henry Ford The beginning Stardust was established in 2013 as a...

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