Alexis Burcin
Alexis Burcin

Reputation: 1

Creating a Menu Catalog and a menu administration form C#

I'm stuck on this program where I have to create Implement a class Pizza which I did

The part where I got stuck sounds like this

Create a class MenuCatalog, that contains pizzas, and implement methods for CRUD operations (Create, Read, Update and Delete).

  1. Add new to pizza to the menu
  2. Delete pizza
  3. Update pizza
  4. Search pizza
  5. Display pizza menu

So far my program looks like this on the pizza class :

using System;
namespace PizzaStore
{
    public class Pizza
    {

        private int _pizzaID;
        private double _price;
        private string _size;
        private Topping _toppings;
       

     

        public Pizza (int pizzaID, double price, string size, Topping toppings)
        {
            _pizzaID = pizzaID;
            _price = price;
            _size = size;
            _toppings = toppings;
           
        }

        public int pizzaID
        {
            get { return _pizzaID; }
            set { _pizzaID = value; }
        }
       

        public double price
        {
            get { return _price; }
            set { _price = value; }
        }


        public string size
        {
            get { return _size; }
            set { _size = value; }
        }

        public Topping toppings
        {
            get { return _toppings; }
            set { _toppings = value; }
        }

        

        public override string ToString()
        {
            return $"The pizza ID is {_pizzaID}, the size is {_size}, with {_toppings.Name}. The price is {_price}.";
        }

      // 
    }

The part where I got really stuck is at the Menu catalog thing :( I'm stuck even at basic stuff such as inserting items, because wherever I search something I'll find different forms that will not work with this.

I tried something like this :

Or I tried with different forms for the inseration such as Pizza p1 = new Pizza( ) ;

Any ideeas on how I should proceed, please? :(

Upvotes: 0

Views: 480

Answers (1)

Christoph Lütjen
Christoph Lütjen

Reputation: 5804

Ok, let's have a look what we need:

  • Pizza class that represents a single pizza
  • MenuCatalog that has a list of all available pizzas and allows us to crud and search
  • Some additional classes that will do something with the data, e.g. render/display it to the user

The PizzaClass

That's done, but you could simplify a little bit to something like this (you need all existing properties, I removed most of them only to keep the demo short).

  public class Pizza
  {
    public Pizza (int id, double price, string size, Topping toppings)
    {
        ID = ID;
        Price = price;
        ...
    }

    public int ID { get; set; }
    public double Price { get; set; }
  }

Changes:

  • Use auto properties
  • Use standard naming convention for properties (pizza.price => pizza.Price)
  • Do not repeat the entity name in property names (pizza.pizzaID => pizza.ID)

The MenuCatalog Class

We want to store a "all available" pizzas, so that will be a list that contains pizzas.

public class MenuCatalog 
{
  private List<Pizza> _allPizzas = new List<Pizza>();
  
  public void Add(Pizza pizza) {
    _allPizzas.Add(pizza);
  }
}

Here you can add all methods to manipulate and search the data.

Display It...

As soon as you have the data part, you can add features that allow users to show and do something with pizzas. How this works depends on the type of your application (HTML, Desktop app, mobile, ...)

Good luck ;-)

Upvotes: 1

Related Questions