Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data;
- namespace Class_Box_Data
- {
- public class StarUp
- {
- static void Main()
- {
- double length = double.Parse(Console.ReadLine());
- double width = double.Parse(Console.ReadLine());
- double height = double.Parse(Console.ReadLine());
- Box box = null;
- try
- {
- box = new Box(length, width, height);
- }
- catch (ArgumentException ae)
- {
- Console.WriteLine(ae.Message);
- return;
- }
- Console.WriteLine($"Surface Area - {box.Surface(box), 0:f2}");
- Console.WriteLine($"Lateral Surface Area - {box.LiteralSurfaceArea(box), 0:f2}");
- Console.WriteLine($"Volume - {box.Volume(box), 0:f2}");
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Transactions;
- namespace Class_Box_Data
- {
- public class Box
- {
- private double length;
- private double width;
- private double height;
- public Box(double length, double width, double height)
- {
- this.Length = length;
- this.Width = width;
- this.Height = height;
- }
- public double Length
- {
- get { return this.length; }
- private set
- {
- if (value <= 0)
- {
- throw new ArgumentException(String.Format(Messages.Validate, nameof(this.Length)));
- }
- this.length = value;
- }
- }
- public double Height
- {
- get { return this.height; }
- private set
- {
- if (value <= 0)
- {
- throw new ArgumentException(String.Format(Messages.Validate, nameof(this.Height)));
- }
- this.height = value;
- }
- }
- public double Width
- {
- get { return this.width; }
- private set
- {
- if (value <= 0)
- {
- throw new ArgumentException(String.Format(Messages.Validate, nameof(this.Width)));
- }
- this.width = value;
- }
- }
- public double Surface(Box box)
- {
- return 2 * (this.Length * this.Width) + 2 * (this.Length * this.Height) + 2*(this.Width * this.Height);
- }
- public double Volume(Box box)
- {
- return this.Width * this.Height * this.Length;
- }
- public double LiteralSurfaceArea(Box box)
- {
- return 2 * (this.Length * this.Height) + 2 * (this.Width * this.Height);
- }
- public override string ToString()
- {
- return base.ToString();
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace Class_Box_Data
- {
- public class Messages
- {
- public const string Validate = "{0} cannot be zero or negative.";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment