/***
Cafeteria *********************************** Ronald works in the school cafeteria. He'd like to have a program that lets him easily type in the names of food items, and then display the prices and add them up. He decided to use a 2-letter abbreviation for each item. Here is a first version of the program. **************************************************/ String food, more ; float price, total; void setup() { do // repeat for each new customer { total = 0.00; do { // repeat for each food item food = input("Food item"); if( food.equals("ha") ) // hamburger { price = 3.50; } else if (food.equals("ff")) // french fries { price = 1.75; } else if (food.equals("ap")) // apple { price = 0.90; } else if (food.equals("dr")) // drink { price = 1.40; } else { price = 0.00; } // unknown item println(food + "\t" + price); total = total + price; } while(!food.equals("")); // press ENTER after last item println("Total = " + total); more = input("Next customer (or type 'quit')"); } while (!more.equals("quit")); } public String input(String prompt) { return javax.swing.JOptionPane.showInputDialog(null,prompt); } |
ha
3.5 ff 1.75 dr 1.4 0.0 Total = 6.65 |