Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. using System;
  2.  
  3. namespace HotelAccounting
  4. {
  5.     public class AccountingModel : ModelBase
  6.     {
  7.         private double price;
  8.         private int nightsCount;
  9.         private double discount;
  10.         private double total;
  11.  
  12.         public double Price
  13.         {
  14.             get { return price; }
  15.             set
  16.             {
  17.                 if (value < 0) throw new ArgumentException();
  18.                 price = value;
  19.  
  20.                 Notify(nameof(Price));
  21.                 Notify(nameof(Total));
  22.             }
  23.         }
  24.  
  25.         public int NightsCount
  26.         {
  27.             get { return nightsCount; }
  28.             set
  29.             {
  30.                 if (value <= 0) throw new ArgumentException();
  31.                 nightsCount = value;
  32.  
  33.                 Notify(nameof(NightsCount));
  34.                 Notify(nameof(Total));
  35.             }
  36.         }
  37.  
  38.         public double Discount
  39.         {
  40.             get { return discount; }
  41.             set
  42.             {
  43.                 if (value >= 100 || value < 0) throw new ArgumentException();
  44.                 discount = value;
  45.  
  46.                 Notify(nameof(Discount));
  47.                 Notify(nameof(Total));
  48.             }
  49.         }
  50.  
  51.         public double Total
  52.         {
  53.             get { return price * nightsCount * (1 - discount / 100); }
  54.             set
  55.             {
  56.                 if (value <= 0) throw new ArgumentException();
  57.                 total = value;
  58.  
  59.                 discount = (100 * (1 - total / (price * nightsCount)));
  60.  
  61.                 Notify(nameof(Total));
  62.                 Notify(nameof(Discount));
  63.             }
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement