Advertisement
Guest User

Toppings

a guest
Nov 1st, 2017
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Pizza_Calories
  8. {
  9.     class Toppings
  10.     {
  11.         private string type;
  12.         private decimal weight;
  13.  
  14.         public string Type
  15.         {
  16.             get
  17.             {
  18.                 return this.type;
  19.             }
  20.  
  21.             set
  22.             {
  23.                 string lowered = value.ToLower();
  24.                 if (lowered == "meat" || lowered == "veggies" || lowered == "cheese" || lowered == "sauce")
  25.                     this.type = value;
  26.                 else
  27.                     throw new Exception("Cannot place " + value + " on top of your pizza.");
  28.             }
  29.         }
  30.  
  31.         public decimal Weight
  32.         {
  33.             get
  34.             {
  35.                 return this.weight;
  36.             }
  37.  
  38.             set
  39.             {
  40.                 if (value >= 1 && value <= 50)
  41.                     this.weight = value;
  42.                 else
  43.                     throw new Exception(this.Type + " weight should be in the range [1..50].");
  44.             }
  45.         }
  46.         public decimal CaloriesCalculator()
  47.         {
  48.             decimal totalCalories = this.weight*2;
  49.             decimal toppingsMultiplier = 0;
  50.             switch (this.Type.ToLower())
  51.             {
  52.                 case "meat":
  53.                     toppingsMultiplier = (decimal)1.2;
  54.                     break;
  55.                 case "veggies":
  56.                     toppingsMultiplier = (decimal)0.8;
  57.                     break;
  58.                 case "cheese":
  59.                     toppingsMultiplier = (decimal)1.1;
  60.                     break;
  61.                 case "sauce":
  62.                     toppingsMultiplier = (decimal)0.9;
  63.                     break;
  64.             }
  65.             totalCalories = totalCalories * toppingsMultiplier;
  66.             return totalCalories;
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement