I've scoured google and SO with no luck so far. It may be due to my lack of knowledge also making it hard to know how to search properly for my answer.
Conceptually, I want to have a method that expects one string, then uses that string within its block of code to guide a basic System.out.println
import java.util.HashMap;
public class Restaurant {
public static void main(String[] args) {
HashMap<String, Integer> restaurantMenu = new HashMap<String, Integer>();
restaurantMenu.put("Turkey Burger",13);
restaurantMenu.put("Naan Pizza",11);
restaurantMenu.put("Cranberry Kale Salad",10);
seePrice("Naan Pizza");
/* I want to create a method called seePrice, which expects a string input
(which will ultimately be a name of one of the food items on the menu).
Then it goes on to use that string input in:
System.out.println(restaurantMenu.get(stringinputgoeshere));
So that I can simply type seePrice("Naan Pizza");
and it will display the price in the console
*/
}
}
After many different attempts, I can't get something so basic to work for me. Please forgive my being such a novice. All help is appreciated.
Edited to the following (note some superfluous items like the sqft lines were added to simply further good practice on setters and getters)
import java.util.HashMap;
public class Restaurant {
//sqft section
private double sqft = 0.0;
public Restaurant(){
sqft = 500.0;
}
public Restaurant(double squareFeet){
sqft = squareFeet;
}
public double getSqft(){
return sqft;
}
//Menu section
private HashMap<String, Double> restaurantMenu = new HashMap<String, Double>();
public int setMenu(HashMap<String, Double> currentMenu){
this.restaurantMenu = currentMenu;
return 1;
}
public HashMap<String, Double> getMenu(){
return restaurantMenu;
}
public static void seePrice (HashMap<String, Double> menu, String food){
System.out.println(menu.get(food));
}
/////////Run Main Section Here
public static void main(String[] args) {
Restaurant platefulOfCox = new Restaurant(2120.8);
System.out.println("The square footage is "+platefulOfCox.getSqft());
HashMap<String, Double> tempMenu = new HashMap <String, Double>();
tempMenu.put("Pizza",10.99);
tempMenu.put("Burger",5.95);
tempMenu.put("Coke",1.99);
platefulOfCox.setMenu(tempMenu);
//Price Checker
String foodItem = "Coke";
seePrice(platefulOfCox.getMenu(),foodItem);
}
}