Advertisement
Guest User

Untitled

a guest
Oct 29th, 2017
605
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.  
  3. class Dough
  4. {
  5.     private string flourType;
  6.     private string bakingTechnique;
  7.     private double weight;
  8.  
  9.     public Dough(string flourType, string bakingTechnique, double weight)
  10.     {
  11.         FlourType = flourType;
  12.         BakingTechnique = bakingTechnique;
  13.         Weight = weight;
  14.     }
  15.  
  16.     public string FlourType
  17.     {
  18.         get
  19.         {
  20.             return flourType;
  21.         }
  22.         set
  23.         {
  24.             if (value.ToLower() != "white" && value.ToLower() != "wholegrain")
  25.             {
  26.                 throw new ArgumentException("Invalid type of dough.");
  27.             }
  28.             flourType = value;
  29.         }
  30.     }
  31.  
  32.     public string BakingTechnique
  33.     {
  34.         get
  35.         {
  36.             return bakingTechnique;
  37.         }
  38.         set
  39.         {
  40.             if (value.ToLower() != "crispy" && value.ToLower() != "chewy" && value.ToLower() != "homemade")
  41.             {
  42.                 throw new ArgumentException("Invalid type of dough.");
  43.             }
  44.             bakingTechnique = value;
  45.         }
  46.     }
  47.  
  48.     public double Weight
  49.     {
  50.         get
  51.         {
  52.             return weight;
  53.         }
  54.         set
  55.         {
  56.             if (value < 1 || value > 200)
  57.             {
  58.                 throw new ArgumentException("Dough weight should be in the range [1..200].");
  59.             }
  60.             weight = value;
  61.         }
  62.     }
  63.  
  64.     public double CalculateCalories()
  65.     {
  66.         double bakingModifier = 0.9;
  67.         if (BakingTechnique.ToLower() == "chewy")
  68.         {
  69.             bakingModifier = 1.1;
  70.         }
  71.         else if (BakingTechnique.ToLower() == "homemade")
  72.         {
  73.             bakingModifier = 1;
  74.         }
  75.  
  76.         double flourModifier = 1.5;
  77.         if (FlourType.ToLower() == "wholegrain")
  78.         {
  79.             flourModifier = 1;
  80.         }
  81.  
  82.         return 2 * weight * bakingModifier * flourModifier;
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement