Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Linq;
- namespace PizzaCalories
- {
- class Pizza
- {
- private string name;
- private Dough dough;
- public Pizza(string name)
- {
- this.Name = name;
- this.Toppings = new List<Topping>();
- }
- public string Name
- {
- get => name;
- set
- {
- if (value.Length<1 || value.Length>15)
- {
- Exception ex = new ArgumentException("Pizza name should be between 1 and 15 symbols.");
- Console.WriteLine(ex.Message);
- Environment.Exit(0);
- }
- name = value;
- }
- }
- private List<Topping> Toppings{get;set;}
- public Dough Dough { get => dough; set => dough = value; }
- public void Add(Topping topping)
- {
- if (this.Toppings.Count > 10)
- {
- Exception ex = new ArgumentException("Number of toppings should be in range [0..10].");
- Console.WriteLine(ex.Message);
- Environment.Exit(0);
- }
- this.Toppings.Add(topping);
- }
- private double GetCalories()
- {
- double doughCalories = this.Dough.DoughCalories;
- double toppingsCalories = this.Toppings.Sum(c=>c.ToppingCalories);
- return doughCalories + toppingsCalories;
- }
- public override string ToString()
- {
- return $"{this.Name} - {this.GetCalories():f2} Calories.";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement