Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
87
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 E01.ClassBox
  4. {
  5.     public class Box
  6.     {
  7.         private double lenght;
  8.         private double width;
  9.         private double height;
  10.  
  11.         public Box(double lenght, double width, double height)
  12.         {
  13.             Lenght = lenght;
  14.             Width = width;
  15.             Height = height;
  16.         }
  17.  
  18.         private double Lenght
  19.         {
  20.             set
  21.             {
  22.                 if (value <= 0)
  23.                 {
  24.                     throw new ArgumentException($"{nameof(Lenght)} cannot be zero or negative.");
  25.                 }
  26.  
  27.                 lenght = value;
  28.             }
  29.         }
  30.  
  31.         private double Width
  32.         {
  33.             set
  34.             {
  35.                 if (value <= 0)
  36.                 {
  37.                     throw new ArgumentException($"{nameof(Width)} cannot be zero or negative.");
  38.                 }
  39.  
  40.                 width = value;
  41.             }
  42.         }
  43.  
  44.         private double Height
  45.         {
  46.             set
  47.             {
  48.                 if (value <= 0)
  49.                 {
  50.                     throw new ArgumentException($"{nameof(Height)} cannot be zero or negative.");
  51.                 }
  52.  
  53.                 height = value;
  54.             }
  55.         }
  56.  
  57.         public double BoxVolume()
  58.         {
  59.             return lenght * width * height;
  60.         }
  61.  
  62.         public double BoxLateralSurfArea()
  63.         {
  64.             return 2 * lenght * height + 2 * width * height;
  65.         }
  66.  
  67.         public double BoxSurfArea()
  68.         {
  69.             return 2 * lenght * width + 2 * lenght * height + 2 * width * height;
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement