Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.21 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 ConsoleApplication15
  8. {
  9.  
  10.     public class Dough
  11.     {
  12.         private string flour;
  13.         private string technique;
  14.         private double weight;
  15.         private double calories;
  16.  
  17.         public string Flour
  18.         {
  19.             get { return flour; }
  20.             set { flour = value; }
  21.         }
  22.  
  23.         public string Technique
  24.         {
  25.             get { return technique; }
  26.             set { technique = value; }
  27.         }
  28.  
  29.         public double Weight
  30.         {
  31.             get { return weight; }
  32.             set
  33.             {
  34.                 if (value < 1 || value > 200)
  35.                 {
  36.                     throw new ArgumentException("Dough weight should be in the range [1..200].");
  37.                 }
  38.                 weight = value;
  39.             }
  40.         }
  41.  
  42.         public double Calories
  43.         {
  44.             get { return calories; }
  45.             private set { calories = value; }
  46.         }
  47.  
  48.         public Dough(string flour, string technique, double weight)
  49.         {
  50.             this.flour = flour;
  51.             this.technique = technique;
  52.             this.weight = weight;
  53.             calories = CalculateCalories();
  54.         }
  55.  
  56.         public double GetFlourValue()
  57.         {
  58.             switch (flour)
  59.             {
  60.                 case "White":
  61.                     return 1.5;
  62.                 case "Wholegrain":
  63.                     return 1.5;
  64.                 default:
  65.                     throw new ArgumentException("Invalid type of dough.");
  66.             }
  67.         }
  68.  
  69.         public double GetTechniqueValue()
  70.         {
  71.             switch (technique)
  72.             {
  73.                 case "Crispy":
  74.                     return 0.9;
  75.                 case "Chewy":
  76.                     return 1.1;
  77.                 case "Homemade":
  78.                     return 1.0;
  79.                 default:
  80.                     throw new ArgumentException("Invalid type of dough.");
  81.             }
  82.         }
  83.  
  84.         private double CalculateCalories()
  85.         {
  86.             return (2.0 * weight) * GetFlourValue() * GetTechniqueValue();
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement