Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Add the following to the FastFood.Java program: 1. Add two more item lists to the right of the two existing item lists. The first contains

Add the following to the FastFood.Java program:

1. Add two more item lists to the right of the two existing item lists. The first contains a list of fruits with these items and their prices, Pear (79 cents), Apple (69 cents), Peach (89 cents), and Banana (59 cents). The second is a list of beverages with these items and their prices, Soda (65 cents), Coffee (95 cents), Orange Juice (85 cents), and Water (55 cents). Display the first list with a label Fruit Items above it and a button Get Fruit Item below it. Display the second list with a label Beverage Items above it and a button Get Beverage Item below it. The new lists and buttons should appear and work in the same way as the ones currently in the program.

2. The button to delete an ordered item does not work currently. Extend the program so that an ordered item can be removed either by double-clicking the item or by first selecting the item with a single mouse click and then pressing the delete button. In either case, the price of the item removed should be deducted from the running total. If no selection is made first, the delete button should do nothing.

3. Add a Clear All button next and to the right of the item delete button and program the button to remove all the items in the ordered list and reset the running total to zero when the button is clicked.

FastFood.Java Code:

// Import Core Java packages import java.awt.*; import java.awt.event.*; public class FastFood extends Frame { // Initial Frame size static final int WIDTH = 400; // frame width static final int HEIGHT = 300; // frame height // Arrays of selection items static final String[] JUNK_FOODS = {"Burger", "Hotdog", "Fries", "Pizza"}; static final int[] JUNK_FOODS_PRICE = {199, 150, 99, 299}; static final String[] DESSERTS = {"Ice cream", "Pie", "Cake", "Donut"}; static final int[] DESSERTS_PRICE = {149, 249, 299, 99}; // List and Button control List junkFoodList; List dessertList; List itemsOrderedList; Button addJunkFood; Button addDessert; Button deleteItem; // Total amount and display Label amountLabel; int amount = 0; /** * Constructor */ public FastFood() { setTitle("Fast Food To Go"); setLayout(new BorderLayout()); // create display for item selection Panel itemPanel = new Panel(new GridLayout(2, 1)); add(itemPanel, BorderLayout.CENTER); // create display and control for junk food selection items Panel junkFoodPanel = new Panel(new BorderLayout()); itemPanel.add(junkFoodPanel); Label junkFood = new Label("Fast Food Items", Label.CENTER); junkFood.setForeground(Color.red); junkFoodPanel.add(junkFood, BorderLayout.NORTH); junkFoodList = new List(); for(int i=0; i= 0) { selectedItem = junkFoodList.getSelectedItem(); itemPrice = JUNK_FOODS_PRICE[selectedIndex]; addOrderedItem(selectedItem, itemPrice); } } else if(event.getSource() == addDessert) { // get item from dessert list selectedIndex = dessertList.getSelectedIndex(); if(selectedIndex >= 0) { selectedItem = dessertList.getSelectedItem(); itemPrice = DESSERTS_PRICE[selectedIndex]; addOrderedItem(selectedItem, itemPrice); } } } } /** * method to add an ordered item */ void addOrderedItem(String item, int price) { itemsOrderedList.add(item); amount += price; amountLabel.setText("$"+(float)amount/100); } /** * the main method */ public static void main(String[] argv) { // Create a frame FastFood frame = new FastFood(); frame.setSize(WIDTH, HEIGHT); frame.setLocation(150, 100); // add window closing listener frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { System.exit(0); } }); // Show the frame frame.setVisible(true); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2000 Database Design

Authors: Louis Davidson

1st Edition

1861004761, 978-1861004765

More Books

Students also viewed these Databases questions

Question

Find Vo(t),t>0 in the network. Discuss it in detail.

Answered: 1 week ago

Question

What is a major limitation of KNN?

Answered: 1 week ago

Question

3. How frequently do the assessments occur?

Answered: 1 week ago