MrDoyle

Hashmap menu

Oct 21st, 2020
718
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.HashMap;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.  
  9.         HashMap<String, Integer> myMenu = new HashMap<String, Integer>();
  10.         myMenu.put("Muffin", 10000);
  11.         myMenu.put("Coffee", 8000);
  12.         myMenu.put("Chocolate", 4000);
  13.  
  14.         System.out.println("These are the items on our Menu");
  15.  
  16.         int menuSlot = 1;
  17.         for (String name:myMenu.keySet()){
  18.             System.out.println("Item #" + menuSlot + ": " + name + " = " + myMenu.get(name));
  19.             menuSlot ++;
  20.         }
  21.  
  22.         String order = " ";
  23.         int orderTotal = 0;
  24.  
  25.         while (!(order.equals("exit")) ){
  26.             System.out.println("Please enter the name of the item you wish to purchase. Type exit when your list is complete");
  27.             order = input.next();
  28.             if (order.equals("exit")){
  29.                break;
  30.             }else{
  31.                 orderTotal = orderTotal + myMenu.get(order);
  32.             }
  33.         }
  34.  
  35.         System.out.println("Your total for this order is: " + orderTotal);
  36.  
  37.     }
  38. }
RAW Paste Data