KostaUrumov

1. Class Box Data

Nov 9th, 2022
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.27 KB | Source Code | 0 0
  1. using System;
  2. using System.Data;
  3.  
  4. namespace Class_Box_Data
  5. {
  6.     public class StarUp
  7.     {
  8.         static void Main()
  9.         {
  10.          
  11.             double length = double.Parse(Console.ReadLine());
  12.             double width = double.Parse(Console.ReadLine());
  13.             double height = double.Parse(Console.ReadLine());
  14.  
  15.             Box box = null;
  16.             try
  17.             {
  18.                 box = new Box(length, width, height);
  19.                
  20.             }
  21.             catch (ArgumentException ae)
  22.             {
  23.  
  24.                 Console.WriteLine(ae.Message);
  25.                 return;
  26.             }
  27.  
  28.              
  29.             Console.WriteLine($"Surface Area - {box.Surface(box), 0:f2}");
  30.             Console.WriteLine($"Lateral Surface Area  - {box.LiteralSurfaceArea(box), 0:f2}");
  31.             Console.WriteLine($"Volume  - {box.Volume(box), 0:f2}");
  32.         }
  33.     }
  34. }
  35.  
  36.  
  37.  
  38.  
  39. using System;
  40. using System.Collections.Generic;
  41. using System.Text;
  42. using System.Transactions;
  43.  
  44. namespace Class_Box_Data
  45. {
  46.     public class Box
  47.     {
  48.        
  49.         private double length;
  50.         private double width;
  51.         private double height;
  52.  
  53.         public Box(double length, double width, double height)
  54.         {
  55.             this.Length = length;
  56.             this.Width = width;
  57.             this.Height = height;
  58.         }
  59.  
  60.         public double Length
  61.         {
  62.             get { return this.length; }
  63.             private set
  64.             {
  65.                 if (value <= 0)
  66.                 {
  67.                     throw new ArgumentException(String.Format(Messages.Validate, nameof(this.Length)));
  68.                 }
  69.                 this.length = value;
  70.  
  71.             }
  72.         }
  73.         public double Height
  74.         {
  75.             get { return this.height; }
  76.             private set
  77.             {
  78.                 if (value <= 0)
  79.                 {
  80.                     throw new ArgumentException(String.Format(Messages.Validate, nameof(this.Height)));
  81.                 }
  82.                 this.height = value;
  83.  
  84.             }
  85.         }
  86.         public double Width
  87.         {
  88.             get { return this.width; }
  89.             private set
  90.             {
  91.                 if (value <= 0)
  92.                 {
  93.                     throw new ArgumentException(String.Format(Messages.Validate, nameof(this.Width)));
  94.                 }
  95.                 this.width = value;
  96.  
  97.             }
  98.         }
  99.  
  100.         public double Surface(Box box)
  101.         {
  102.            
  103.             return  2 * (this.Length * this.Width) + 2 * (this.Length * this.Height) + 2*(this.Width * this.Height);
  104.            
  105.            
  106.         }
  107.         public double Volume(Box box)
  108.         {
  109.             return  this.Width * this.Height * this.Length;
  110.            
  111.  
  112.         }
  113.         public double LiteralSurfaceArea(Box box)
  114.         {
  115.             return 2 * (this.Length * this.Height) + 2 * (this.Width * this.Height);
  116.            
  117.  
  118.         }
  119.  
  120.         public override string ToString()
  121.         {
  122.             return base.ToString();
  123.         }
  124.  
  125.  
  126.     }
  127. }
  128.  
  129.  
  130.  
  131.  
  132. using System;
  133. using System.Collections.Generic;
  134. using System.Text;
  135.  
  136. namespace Class_Box_Data
  137. {
  138.     public class Messages
  139.     {
  140.         public const string Validate = "{0} cannot be zero or negative.";
  141.     }
  142. }
  143.  
  144.  
Advertisement
Add Comment
Please, Sign In to add comment