Skip to content
Advertisement

Method to display particular types of pizza from a list in Java

I have a simple pizza program in Java, made using the Factory Pattern. Basically, when a factory is given as a parameter, it creates a particular pizza, which is then added to the list of pizzas of the PizzaShop.

I would like to create a method that displays how many particular pizzas I have. For instance, when the method is called, I would like it to display something like “We have 5 PizzaChicago and 3 PizzaNewYork”. I am not sure how to do that.

This is my code.

JavaScript

Advertisement

Answer

What you have to do is iterate the list and check what is the type of every object.

JavaScript
Advertisement