Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace PizzaCalories
- {
- using System;
- public class Topping
- {
- private const double MAX_WEIGHT = 50;
- private const double MIN_WEIGHT = 0;
- 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
- {
- return this.name;
- }
- private set
- {
- if (value.ToLower() != "meat" && value.ToLower() != "veggies" && value.ToLower() != "cheese" && value.ToLower() != "sauce")
- {
- throw new ArgumentException(string.Format(ExceptionMessages.Exception.invalidToppingNameException, value));
- }
- this.name = value;
- }
- }
- public double Weight
- {
- get
- {
- return this.weight;
- }
- private set
- {
- if (value < MIN_WEIGHT || value > MAX_WEIGHT)
- {
- throw new ArgumentException(string.Format(ExceptionMessages.Exception.invalidToppingWeightException,this.Name));
- }
- this.weight = value;
- }
- }
- public double CalculateCalories()
- {
- double calories = 0.0;
- if (this.Name == "meat")
- {
- calories = 2 * (this.weight * meat);
- }
- else if (this.Name == "veggies")
- {
- calories = 2 * (this.weight * veggies);
- }
- else if (this.Name == "cheese")
- {
- calories = 2 * (this.weight * cheese);
- }
- else if (this.Name == "sauce")
- {
- calories = 2 * (this.weight * sauce);
- }
- return calories;
- }
- }
- }
Add Comment
Please, Sign In to add comment