straight to the point with this one. I just need some general guidance on whether the program i've written will actually work correctly with Hashmaps and just my approach to trying to complete tasks in general.(ive tried compiling it and it throws an error with line 90 regarding the else statement, think my brackets are messed up)
The purpose of the first function is to have the user input an order of upto 5 characters in one line(havent written anything to check this yet), the first character must be M or L for medium or large pizza. Its then followed by 0 to 4 characters for the toppings.
the second function purpose is the same as the first, only it shoudnt allow 3 or more of the same toppings.
public class Exercise_1{
public static void pizzaServiceA(String args[]){
HashMap <Character, String> Toppings = new Hashmap <Character, String>();
//pizza
dictionary.put("m", "meduim");
dictionary.put("l", "large");
//topping
dictionary.put("h", "ham");
dictionary.put("m", "mozzerella");
dictionary.put("o", "olives");
dictionary.put("p", "pineapple");
dictionary.put("s", "spinach");
dictionary.put("H", "ham");
dictionary.put("M", "mozzerella");
dictionary.put("O", "olives");
dictionary.put("P", "pineapple");
dictionary.put("S", "spinach");
HashMap <Character, Double> Prices = new Hashmap <Character, Double>();
//pizza price
dictionary.put("m", 4.00);
dictionary.put("l", 5.00);
//topping price medium
dictionary.put("h", 1.40);
dictionary.put("m", 1.00);
dictionary.put("o", 0.80);
dictionary.put("p", 1.00);
dictionary.put("s", 1.20);
//topping price large
dictionary.put("H", 2.10);
dictionary.put("M", 1.50);
dictionary.put("O", 1.20);
dictionary.put("P", 1.50);
dictionary.put("S", 1.20);
System.out.println("Enter a pizza order: ");
Scanner reader = new Scanner(System.in);
String orders = reader.nextLine();
Char[] orderLetters = orders.toCharArray();
String fullOrder = "";
Double fullPrice = 0.0;
//check if sequence enters it more than 5 characters
if (input.equals("quit")) {
System.out.println("Quitting.");
System.exit(0);
}
else if (!(order[0].equals('l')))
{
System.out.println("Please enter the size of your pizza, m or l");
}
else if (!(order[0].equals('m')))
{
System.out.println("Please enter the size of your pizza, m or l");
}
for(Char orderLetters : c.toCharArray())
{
Double price = Prices.get(orderLetters);
fullPrice += price;
String type = Toppings.get(orderLetters);
if(type == 'm' || type == 'l')
{
fullOrder += type + " pizza with ";
}
else
{
fullOrder += type + ",";
}
}
fullOrder += fullPrice;
System.out.printf("%.2f", "£", fullOrder);
}
public static void pizzaServiceB(){
Map<Character, Integer> map = new Hashmap<Character, Integer>();
for(int i = 0; i <s.length(); i++){
char orderLetters = c.charAt(i); //s.charAt?
if (map.containsKey(orderLetters)){
int c = map.get(orderLetters); //counts letters in orderletters
map.put(orderLetters, ++c);
{
else
{
map.put(orderLetters, 1);
}
}
}
}
if (c.equals() = 3){
System.out.println("You cannot order "); //if topping occurs 3 times print
}
//same functionality of A but orders with more than 3 toppings shoudlnt be allowed
}
public static void main(){
Exercise_1 ex1 = null;
ex1.testpizzaServiceA();
//ex1.testpizzaServiceB();
}
}