Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This program is for an intro level Java course. The idea is to create a custom s

ID: 3825957 • Letter: T

Question

This program is for an intro level Java course. The idea is to create a custom sandwich ordering system. As the program runs, the user is given options (length, bread type, meat, cheese, toppings, and sauces) to create their ideal meal. Each option (variable) should also have a corresponding value that reflects the price of each item. After they select what they want, the program should display a price total that corresponds to the number of things they selected. Lastly, the program should print the list of items and price total to an external Notepad file.

The inputs should be done with the 'Scanner' method. The program must run in a compiler (Netbeans) as it will be presented and demonstrated.

Here are the techniques looked for in this project:

1. for/while loops

2. if/else conditions or nested if/else

3. functions constructed by you

4. in-built functions

5. Scanner class

6. Imported libraries

7. Data structures like Arrays, List, Maps. Use of more complex data structures like Maps will be given brownie points

8. Read/Write from an external file

9. Appropriate use of classes and objects

Please contact me with more questions.

Explanation / Answer

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class sandvich {
  
  
   public static void main(String args[]) throws IOException
   {
       File file = new File("C:/Users/Sunakshi/Desktop/Sandvich_order.txt");
       BufferedWriter output = new BufferedWriter(new FileWriter(file));
       int price_total=0;
       Map<String,Integer> final_order=new HashMap<String,Integer>();
       length_function(final_order);
       bread_type_function(final_order);
       meat_function(final_order);
       cheese_function(final_order);
       topping_function(final_order);
       sauce_function(final_order);       try
       {
           for(Entry<String, Integer> entry : final_order.entrySet())
           {   //print keys and values
               //System.out.println("entry.getValue()"+entry.getValue().intValue());
               price_total = price_total +entry.getValue().intValue();
                     output.write(entry.getKey() + " Price is " +entry.getValue());
           }
       output.write("Final Price is "+price_total);
       output.close();
       }
       catch(Exception e)
       {
           e.printStackTrace();
       }
   }
  
   static public void length_function(Map final_order)
   {
       System.out.println("Please spcify the length of sandvich");
       Map<String,Integer> length_values=new HashMap<String,Integer>();
       length_values.put("25mm",25);
       length_values.put("50mm",30);
       length_values.put("75mm",35);
       length_values.put("100mm",40);
       int i=1;
       for(Entry<String, Integer> entry : length_values.entrySet())
            {   //print keys and values
                 System.out.println(entry.getKey() + " Price is " +entry.getValue());
                 i++;
            }
       System.out.println("Please enter the corresponding length of sandvich");
       Scanner sc= new Scanner(System.in);
       String choose_option = sc.nextLine();
       String key = "Length : "+choose_option;
       final_order.put(key,length_values.get(choose_option));
      
   }
  
  
   static public void bread_type_function(Map final_order)
   {
       System.out.println("Please spcify the bread type of sandvich");
       Map<String,Integer> bread_values=new HashMap<String,Integer>();
       bread_values.put("thin",25);
       bread_values.put("medium",30);
       bread_values.put("thick",35);
       int i=1;
       for(Entry<String, Integer> entry : bread_values.entrySet())
            {   //print keys and values
                 System.out.println(i+". For Bread "+entry.getKey() + " Price is " +entry.getValue());
                 i++;
            }
       System.out.println("Please enter the corresponding bread type of sandvich");
       Scanner sc= new Scanner(System.in);
       String choose_option = sc.nextLine();
       String key = "Bread type : "+choose_option;
       final_order.put(key,bread_values.get(choose_option));
      
   }
  
  
   static public void meat_function(Map final_order)
   {
       System.out.println("Please spcify the meat type of sandvich");
       Map<String,Integer> meat_values=new HashMap<String,Integer>();
       meat_values.put("chicken",25);
       meat_values.put("fish",30);
       meat_values.put("turkey",35);
       int i=1;
       for(Entry<String, Integer> entry : meat_values.entrySet())
            {   //print keys and values
                 System.out.println(i+". For Meat Type "+entry.getKey() + " Price is " +entry.getValue());
                 i++;
            }
       System.out.println("Please enter the corresponding meat type of sandvich");
       Scanner sc= new Scanner(System.in);
       String choose_option = sc.nextLine();
       String key = "Meat Type : "+choose_option;
       final_order.put(key,meat_values.get(choose_option));
      
   }
  
   static public void cheese_function(Map final_order)
   {
       System.out.println("Please spcify the cheese type of sandvich");
       Map<String,Integer> cheese_values=new HashMap<String,Integer>();
       cheese_values.put("normal",25);
       cheese_values.put("medium",30);
       cheese_values.put("extra",35);
       int i=1;
       for(Entry<String, Integer> entry : cheese_values.entrySet())
            {   //print keys and values
                 System.out.println(i+". For Cheese Type "+entry.getKey() + " Price is " +entry.getValue());
                 i++;
            }
       System.out.println("Please enter the corresponding Cheese type of sandvich");
       Scanner sc= new Scanner(System.in);
       String choose_option = sc.nextLine();
       String key = "Cheese Type : "+choose_option;
       final_order.put(key,cheese_values.get(choose_option));
      
   }
  
   static public void topping_function(Map final_order)
   {
       System.out.println("Please spcify the Topping type of sandvich");
       Map<String,Integer> topping_values=new HashMap<String,Integer>();
       topping_values.put("olives",25);
       topping_values.put("corn",30);
       topping_values.put("bean",35);
       int i=1;
       for(Entry<String, Integer> entry : topping_values.entrySet())
            {   //print keys and values
                 System.out.println(i+". For Topping Type "+entry.getKey() + " Price is " +entry.getValue());
                 i++;
            }
       System.out.println("Please enter the corresponding Topping type of sandvich");
       Scanner sc= new Scanner(System.in);
       String choose_option = sc.nextLine();
       String key = "Topping Type : "+choose_option;
       final_order.put(key,topping_values.get(choose_option));
      
   }
  
   static public void sauce_function(Map final_order)
   {
       System.out.println("Please spcify the Sauce for sandvich");
       Map<String,Integer> meat_values=new HashMap<String,Integer>();
       meat_values.put("red",25);
       meat_values.put("white",30);
       meat_values.put("mix",35);
       int i=1;
       for(Entry<String, Integer> entry : meat_values.entrySet())
            {   //print keys and values
                 System.out.println(i+". For Sauce "+entry.getKey() + " Price is " +entry.getValue());
                 i++;
            }
       System.out.println("Please enter the corresponding Sauce of sandvich");
       Scanner sc= new Scanner(System.in);
       String choose_option = sc.nextLine();
       String key = "Sauce Type : "+choose_option;
       final_order.put(key,meat_values.get(choose_option));
      
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote