Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace PizzaCalories
- {
- public class Topping
- {
- private const double MinWeight = 1;
- private const double MaxWeight = 50;
- private const double meat = 1.2;
- private const double veggies = 0.8;
- private const double cheese = 1.1;
- private const double sauce = 0.9;
- private string name;
- private double weight;
- public Topping(string name, double weight)
- {
- this.Name = name;
- this.Weight = weight;
- }
- public string Name
- {
- get => this.name;
- set
- {
- if (value.ToLower() != "meat" && value.ToLower() != "veggies" &&
- value.ToLower() != "cheese" && value.ToLower() != "sauce")
- {
- throw new InvalidOperationException(String.Format
- (Exceptions.InvalidToppingNameException, value));
- }
- this.name = value;
- }
- }
- public double Weight
- {
- get => this.weight;
- set
- {
- if (value < MinWeight || value > MaxWeight)
- {
- throw new InvalidOperationException(String.Format
- (Exceptions.InvalidToppingWeightException, this.Name));
- }
- this.weight = value;
- }
- }
- public double CalculateCalories()
- {
- double calories = 0.0;
- switch (Name.ToLower())
- {
- case "meat": calories = 2 * this.Weight * meat; break;
- case "veggies": calories = 2 * this.Weight * veggies; break;
- case "cheese": calories = 2 * this.Weight * cheese; break;
- case "sauce": calories = 2 * this.Weight * sauce; break;
- default:
- break;
- }
- return calories;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement