social1986

Untitled

Feb 21st, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using System;
  2.  
  3. public class Box
  4. {
  5.     private double length;
  6.     private double width;
  7.     private double height;
  8.  
  9.     public Box(double length, double width, double height)
  10.     {
  11.         this.Length = length;
  12.         this.Width = width;
  13.         this.Height = height;
  14.     }
  15.  
  16.     public double Length
  17.     {
  18.         get { return this.length; }
  19.         private set
  20.         {
  21.             if (!ValidateInput(value))
  22.             {
  23.                 throw new ArgumentException("Length cannot be zero or negative.");
  24.             }
  25.             this.length = value;
  26.         }
  27.     }
  28.  
  29.     public double Width
  30.     {
  31.         get { return this.width; }
  32.         private set
  33.         {
  34.             if (!ValidateInput(value))
  35.             {
  36.                 throw new ArgumentException("Width cannot be zero or negative.");
  37.             }
  38.             this.width = value;
  39.         }
  40.     }
  41.  
  42.     public double Height
  43.     {
  44.         get { return this.height; }
  45.         private set
  46.         {
  47.             if (!ValidateInput(value))
  48.             {
  49.                 throw new ArgumentException("Height cannot be zero or negative.");
  50.             }
  51.             this.height = value;
  52.         }
  53.     }
  54.  
  55.  
  56.  
  57.     public double SurfaceArea()
  58.     {
  59.         return 2 * length * width + 2 * length * height + 2 * width * height;
  60.     }
  61.  
  62.     public double LateralSurfaceArea()
  63.     {
  64.         return 2 * length * height + 2 * width * height;
  65.     }
  66.  
  67.     public double Volume()
  68.     {
  69.         return length * width * height;
  70.     }
  71.  
  72.     private bool ValidateInput(double value)
  73.     {
  74.         return value > 0;
  75.     }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment