Guest User

Untitled

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