Advertisement
Guest User

Class Box Data 75/100

a guest
Jul 10th, 2020
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace P01.ClassBoxData
  6. {
  7.     public class Box
  8.     {
  9.         private const double SIDE_MIN_VALUE = 0;
  10.         private const string INVALID_SIDE_MESSEGE = "{0} cannot be zero or negative.";
  11.         private double length;
  12.         private double width;
  13.         private double height;
  14.  
  15.         public Box(double length, double width, double height)
  16.         {
  17.             this.Lenght = length;
  18.             this.Width = width;
  19.             this.Height = height;
  20.         }
  21.         public double Lenght
  22.         {
  23.             get => this.length;
  24.             private set
  25.             {
  26.                 this.ValidateSide(value, nameof(this.Lenght));
  27.                 this.length = value;
  28.             }
  29.         }
  30.         public double Width
  31.         {
  32.             get => this.width;
  33.             private set
  34.             {
  35.                 this.ValidateSide(value, nameof(this.Width));
  36.                 this.width = value;
  37.             }
  38.         }
  39.         public double Height
  40.         {
  41.             get => this.height;
  42.             private set
  43.             {
  44.                 this.ValidateSide(value, nameof(this.Height));
  45.                 this.height = value;
  46.             }
  47.         }
  48.  
  49.         private void ValidateSide(double value, string side)
  50.         {
  51.             if (value <= SIDE_MIN_VALUE)
  52.             {
  53.                 throw new ArgumentException(String.Format(INVALID_SIDE_MESSEGE, side));
  54.             }
  55.         }
  56.  
  57.         public double SurfaceArea()
  58.         {
  59.             double area = 2 * (this.Lenght * this.Width) + 2 * (this.Lenght * this.Height) + 2 * (this.Width * this.Height);
  60.             return area;
  61.         }
  62.  
  63.         public double LateralSurfaceArea()
  64.         {
  65.             double lateralSurfaceArea = 2 * this.Lenght * this.Height + 2 * this.Width * this.Height;
  66.             return lateralSurfaceArea;
  67.         }
  68.         public double Volume()
  69.         {
  70.             double volume = this.Width * this.Lenght * this.Height;
  71.             return volume;
  72.         }
  73.  
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement