I currently have multiple code like this for different toppings
// Toppings - Egg
System.out.print("Do you want " + egg.getType() + "?");
input = keyboard.nextLine();
choice = input.charAt(0);
if (choice == 'y') {
l.add(egg.getType());
c.add((double) egg.getCost());
numberOfToppings = numberOfToppings + 1;
totalToppingPrice = totalToppingPrice + egg.getCost();
toppings = toppings + "Egg";
}
It works fine, however i was hoping i could do all toppings in just one block of code. Because i've got around 5 of these, and it takes up far too much, and i've been advised to do so. Anyone got any ideas for how this could be done ? thanks
choice) with object to get polymorphism with strategy/state pattern