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;
- using System.Threading.Tasks;
- namespace Pizza_Calories
- {
- class Toppings
- {
- private string type;
- private decimal weight;
- public string Type
- {
- get
- {
- return this.type;
- }
- set
- {
- string lowered = value.ToLower();
- if (lowered == "meat" || lowered == "veggies" || lowered == "cheese" || lowered == "sauce")
- this.type = value;
- else
- throw new Exception("Cannot place " + value + " on top of your pizza.");
- }
- }
- public decimal Weight
- {
- get
- {
- return this.weight;
- }
- set
- {
- if (value >= 1 && value <= 50)
- this.weight = value;
- else
- throw new Exception(this.Type + " weight should be in the range [1..50].");
- }
- }
- public decimal CaloriesCalculator()
- {
- decimal totalCalories = this.weight*2;
- decimal toppingsMultiplier = 0;
- switch (this.Type.ToLower())
- {
- case "meat":
- toppingsMultiplier = (decimal)1.2;
- break;
- case "veggies":
- toppingsMultiplier = (decimal)0.8;
- break;
- case "cheese":
- toppingsMultiplier = (decimal)1.1;
- break;
- case "sauce":
- toppingsMultiplier = (decimal)0.9;
- break;
- }
- totalCalories = totalCalories * toppingsMultiplier;
- return totalCalories;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement